smsprotocols/smsstack/gsmu/inc/Gsmumsg.h
changeset 0 3553901f7fa8
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 1999-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This file defines the class CSmsMessage
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21  @publishedAll
       
    22 */
       
    23 
       
    24 #ifndef __GSMUMSG_H__
       
    25 #define __GSMUMSG_H__
       
    26 
       
    27 #include <e32std.h>
       
    28 #include <f32file.h>
       
    29 #include <gsmuetel.h>
       
    30 #include <charconv.h>
       
    31 #include <gsmunmspacemobstore.h>
       
    32 #include "gsmupdu.h"
       
    33 
       
    34 #include <emsinformationelement.h>
       
    35 
       
    36 /**
       
    37  *  @publishedAll
       
    38  */
       
    39 const TUint IoctlWriteSMSBufferSize = 256;
       
    40 const TUint KMaxMobileNameSize = 32;
       
    41 
       
    42 class CSmsBufferBase;
       
    43 class CSmsCompressedBuffer;
       
    44 class TSmsUserDataSettings;
       
    45 class CSmsEMSBufferSegmenter;
       
    46 class CEmsUserPrompt;
       
    47 class CEmsObjectDistribution;
       
    48 class CSmsIEOperation;
       
    49 class CSmsNonIEOperation;
       
    50 class CSmsMessageAdditionalAttributes;
       
    51 
       
    52 /**
       
    53  *  This class is used in CSmsMessage only.
       
    54  *  @publishedAll
       
    55  */
       
    56 class TGsmSmsSlotEntry
       
    57 	{
       
    58 public:
       
    59 	IMPORT_C TGsmSmsSlotEntry();
       
    60 
       
    61 public:
       
    62     TInt iIndex;
       
    63     TBuf<KMaxMobileNameSize> iStore; 				// equivalent to RMobilePhone::TMobileName
       
    64 	void InternalizeL(RReadStream& aStream);
       
    65 	void ExternalizeL(RWriteStream& aStream) const;
       
    66     };
       
    67 
       
    68 struct TEncodeParams
       
    69 	{
       
    70 	const TTime* iTimeStamp;
       
    71 	const TTimeIntervalSeconds* iTimeIntervalInSeconds;		
       
    72 	};
       
    73 
       
    74 /**
       
    75  *  Represents a complete SMS message.
       
    76  *  
       
    77  *  This class can:
       
    78  *  
       
    79  *  Internalise and externalise its data
       
    80  *  
       
    81  *  Encode/decode itself to/from one or more SMS PDU's
       
    82  *  
       
    83  *  SMS Message Data is stored in the CSmsBufferBase iBuffer. SMS Message Settings
       
    84  *  are stored in the CSmsPDU iSmsPDU.
       
    85  *  @publishedAll
       
    86  *  @released 
       
    87  */
       
    88 class CSmsMessage : public CBase
       
    89 	{
       
    90 public:
       
    91 /** User data optimisation flags. */
       
    92 	enum TSmsOptimizationFlags
       
    93 		{
       
    94 	/**
       
    95 	 *  The alphabet flag causes an alphabet to be chosen which preserves information
       
    96 	 *  	in the message and makes the number of PDUs as small as possible. 
       
    97 	 */
       
    98 		ESmsFlagOptimizeAlphabet=0x01,
       
    99 	/**
       
   100 	 *  8-bit referenced concatenation.
       
   101 	 *  
       
   102 	 *  This causes compression to be switched off and if the message length is greater
       
   103 	 *  	than the maximum message length, concatenation is switched on. 
       
   104 	 */
       
   105 		ESmsFlagOptimizeConcatenation=0x08,
       
   106 	/**
       
   107 	 *  16-bit referenced concatenation.
       
   108 	 *  
       
   109 	 *  This causes compression to be switched off and if the message length is greater
       
   110 	 *  	than the maximum message length, concatenation is switched on. 
       
   111 	 */
       
   112 		ESmsFlagOptimizeConcatenation16BitReference=0x10,
       
   113 		};
       
   114 
       
   115 /** Flags that indicate whether a message is stored. */
       
   116 	enum TMobileSmsStorage
       
   117 		{
       
   118 	/** No storage. */
       
   119 		ESmsNoStorage=0x00,
       
   120 	/** SIM storage. */
       
   121 		ESmsSIMStorage=0x04,
       
   122 	/** Phone storage. */
       
   123 		ESmsPhoneStorage=0x08,
       
   124 	/** Combined storage. */
       
   125 		ESmsCombinedStorage=0x0C
       
   126 		};
       
   127 
       
   128 	enum TTimeIntervalsRepresentedInSeconds
       
   129 		{
       
   130 		E15MinutesRepresentedInSeconds = 15 * 60,
       
   131 		EMaximumSeconds                = 79 * E15MinutesRepresentedInSeconds
       
   132 		                                      // Harmonised with maximum offset allowed for
       
   133                                               // Service Centre Time Stamp per 23.040 V4.4 Sect 9.2.3.11.
       
   134 		};
       
   135 
       
   136 
       
   137 public:
       
   138 	IMPORT_C static CSmsMessage* NewL(RFs& aFs, const TGsmSms& aGsmSms,CSmsBufferBase* aBuffer, TBool aIsRPError=EFalse,TBool aIsMobileTerminated=ETrue);
       
   139 	IMPORT_C static CSmsMessage* NewL(RFs& aFs, CSmsPDU::TSmsPDUType aType,CSmsBufferBase* aBuffer,TBool aIsRPError=EFalse);
       
   140 	IMPORT_C ~CSmsMessage();
       
   141 
       
   142 	inline CSmsPDU::TSmsPDUType Type() const;
       
   143 	inline TBool IsComplete() const;
       
   144 	inline TBool IsDecoded() const;
       
   145 	inline TMobileSmsStorage Storage() const;
       
   146 	inline void SetStorage(TMobileSmsStorage aStorage);
       
   147 	inline NMobileSmsStore::TMobileSmsStoreStatus Status() const;
       
   148 	inline void SetStatus(NMobileSmsStore::TMobileSmsStoreStatus aStatus);
       
   149 	inline TInt LogServerId() const;
       
   150 	inline void SetLogServerId(TInt aId);
       
   151 	inline const TTime& Time() const;
       
   152 	inline void SetTime(const TTime& aTime);
       
   153 	IMPORT_C TTimeIntervalSeconds UTCOffset() const;
       
   154 	IMPORT_C TBool SetUTCOffset(const TTimeIntervalSeconds& aTimeOffset);
       
   155     IMPORT_C void  SetDecodedOnSIM(TBool aOnSim);
       
   156     IMPORT_C TBool DecodedOnSim();
       
   157     IMPORT_C void  SetForwardToClient(TBool aForward);
       
   158     IMPORT_C TBool ForwardToClient();
       
   159 
       
   160 	inline CSmsPDU& SmsPDU();
       
   161 	inline const CSmsPDU& SmsPDU() const;
       
   162 
       
   163 	inline TPtrC ServiceCenterAddress() const;
       
   164 	inline void SetServiceCenterAddressL(const TDesC& aAddress);
       
   165 	inline void ParsedServiceCenterAddress(TGsmSmsTelNumber& aParsedAddress) const;
       
   166 	inline void SetParsedServiceCenterAddressL(const TGsmSmsTelNumber& aParsedAddress);
       
   167 
       
   168 	inline TPtrC ToFromAddress() const;
       
   169 	inline void SetToFromAddressL(const TDesC& aAddress);
       
   170 	inline void ParsedToFromAddress(TGsmSmsTelNumber& aParsedAddress) const;
       
   171 	inline void SetParsedToFromAddressL(const TGsmSmsTelNumber& aParsedAddress);
       
   172 
       
   173 	IMPORT_C void InternalizeWithoutBufferL(RReadStream& aStream);
       
   174 	IMPORT_C void ExternalizeWithoutBufferL(RWriteStream& aStream) const;
       
   175 
       
   176 	IMPORT_C void InternalizeL(RReadStream& aStream);
       
   177 	IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
       
   178 
       
   179 	inline CSmsBufferBase& Buffer();
       
   180 	inline const CSmsBufferBase& Buffer() const;
       
   181 
       
   182 //  Functions related to encoding/decoding the text buffer
       
   183 	IMPORT_C TBool TextPresent() const;
       
   184 	IMPORT_C TInt NumMessagePDUsL();
       
   185 	IMPORT_C TInt MaxMessageLength() const;
       
   186 	IMPORT_C TInt MessageLengthL();
       
   187 	IMPORT_C void GetEncodingInfoL(TInt& aPdus, TInt& aUnconvertedChars,
       
   188                                    TInt& aDowngradedChars, TInt& aFreeUDUnitsInLastPDU);
       
   189 
       
   190 	IMPORT_C void UserDataSettings(TSmsUserDataSettings& aSettings) const;
       
   191 	IMPORT_C void SetUserDataSettingsL(const TSmsUserDataSettings& aSettings);
       
   192 	IMPORT_C void OptimizeSettingsL(TInt aOptions);
       
   193 
       
   194 	IMPORT_C TSmsEncoding Alternative7bitEncoding() const;
       
   195 	IMPORT_C TInt SetAlternative7bitEncoding(TSmsEncoding aEncoding);
       
   196 	IMPORT_C TBool IsSupportedL(const TDesC& aDes,TInt& aNumberOfUnconvertibleCharacters, TInt& aIndexOfFirstUnconvertibleCharacter);
       
   197 	IMPORT_C TBool IsSupportedL(const TDesC& aDes, TInt& aNumberOfUnconvertibleCharacters,
       
   198 			                    TInt& aNumberOfDowngradedCharacters,
       
   199 			                    TInt& aNumberRequiringAlternativeEncoding,
       
   200 			                    TInt& aIndexOfFirstUnconvertibleCharacter) const;
       
   201 
       
   202 	IMPORT_C void EncodeMessagePDUsL(CArrayFix<TGsmSms>& aSmsArray, TInt aReference=0);
       
   203 	IMPORT_C void DecodeMessagePDUsL(const CArrayFix<TGsmSms>& aSmsArray);
       
   204 	IMPORT_C const RPointerArray<const CEmsInformationElement>& GetEMSInformationElementsL()const;
       
   205 	IMPORT_C void AddEMSInformationElementL(const CEmsInformationElement& aEmsIE);
       
   206 	IMPORT_C RPointerArray<CEmsInformationElement>* RemoveEMSInformationElementsL(const TUint aStartPosition,const TSmsId aEmsId);
       
   207 	IMPORT_C CEmsInformationElement* RemoveEMSInformationElementL(const TUint aStartPosition,const TSmsId aEmsId);
       
   208 	IMPORT_C void ResetEMSL();
       
   209 	IMPORT_C TBool EncodeIntoSinglePDUL(CArrayFix<TGsmSms>& aSmsArray);
       
   210 	IMPORT_C void CopyEmsElementsL(CSmsMessage& aToMessage) const;
       
   211 	IMPORT_C void AddSlotL(const TGsmSmsSlotEntry& aSlot);
       
   212 	IMPORT_C TBool MatchSlots(const CArrayFixFlat<TGsmSmsSlotEntry>& aSlotArray);
       
   213 // E-mail header
       
   214  	IMPORT_C void AddEmailHeaderL(const TDesC& aEmailHeader,const TDesC& aEmailBody);
       
   215  	IMPORT_C TBool IsEmailHeader() const;
       
   216  	IMPORT_C TBool GetEmailHeaderL(HBufC** aEmailHeader,HBufC** aEmailBody);
       
   217  	void InstallEmailHeaderInformationElementL(CSmsUserData& aUserData,TInt& aHeaderLength);
       
   218  	void InstallEmailHeaderInformationElementL(CSmsCommand& aCommand,TInt& aHeaderLength);
       
   219 	inline void Set16BitConcatenation(TBool aIs16BitConcatenation);
       
   220 	inline TBool Is16BitConcatenation()const;
       
   221 	IMPORT_C void UpdateSlotsL(TDesC8& aBuf);
       
   222 // Version information
       
   223 	IMPORT_C TInt Version();
       
   224 	// from this point downwards, all functions should be published internally only
       
   225 	IMPORT_C TInt SetVersion(TInt aVersion);
       
   226  	IMPORT_C void InternalizeWithoutBufferAndVersionL(RReadStream& aStream);
       
   227 	IMPORT_C void ExternalizeWithoutBufferAndVersionL(RWriteStream& aStream) const;
       
   228  	IMPORT_C void InternalizeBufferL(RReadStream& aStream);
       
   229 	IMPORT_C void ExternalizeBufferL(RWriteStream& aStream) const;
       
   230  	IMPORT_C void InternalizeVersionL(RReadStream& aStream);
       
   231 	IMPORT_C void ExternalizeVersionL(RWriteStream& aStream) const;
       
   232 
       
   233     void* AdditionalInfo() {return (void*)iAdditionalInfo;};
       
   234     IMPORT_C CSmsIEOperation& GetOperationsForIEL(CSmsInformationElement::TSmsInformationElementIdentifier) const;
       
   235     IMPORT_C CSmsNonIEOperation& GetOperationsForNonIEL(TSmsNonIEIdentifier) const;
       
   236     
       
   237   	IMPORT_C TSmsStatusReportScheme Scheme() const;
       
   238 	IMPORT_C void DecodePartialCompleteMessagePDUsL(const CArrayFix<TGsmSms>& aSmsArray, TBool aLastPartialCompleteMsg);
       
   239 
       
   240 private:
       
   241 
       
   242 	CSmsMessage(RFs& aFs, CSmsBufferBase* aBuffer);
       
   243 	void ConstructL(const TGsmSms& aGsmSms, TBool aIsRPError,TBool aIsMobileTerminated);
       
   244 	void ConstructL(CSmsPDU::TSmsPDUType aType,TBool aIsRPError);
       
   245 
       
   246 	void CreateControlIEOperationsClassesL();
       
   247 	void CreateControlNonIEOperationsClassesL();
       
   248 
       
   249 	inline void SetIsComplete(TBool aIsComplete);
       
   250 	inline void SetIsDecoded(TBool aIsDecoded);
       
   251 
       
   252 
       
   253 	inline TBool BinaryData() const;
       
   254 	TInt ConvertedBufferLengthL(const CSmsBufferBase& aBuffer);
       
   255 	void EncodeBufferL(CArrayFix<TGsmSms>& aSmsArray,TInt aReference,const CSmsBufferBase& aBuffer,
       
   256 			           TInt& aUnconvertedChars, TInt& aDowngradedChars,
       
   257 			           TInt& aFreeUDUnitsInLastPDU, TBool aDoEncode=ETrue);
       
   258 	void DecodeBufferL(CArrayPtr<CSmsPDU>& aSmsPDUArray,CSmsBufferBase& aBuffer);
       
   259 	TBool EncodeIntoSinglePDUL(CArrayFix<TGsmSms>& aSmsArray, TInt& aUnconvertedChars,
       
   260 			                   TInt& aDowngradedChars, TInt& aFreeUDUnitsInLastPDU);
       
   261 	void PrepareCommandMessageL(void);
       
   262 	void InstallEmsInformationElementsL(CSmsUserData& aUserData, TInt aStartPosition);
       
   263 	void InstallEmsInformationElementsL(CSmsCommand& aCommand, TInt aStartPosition);
       
   264 	void InstallControlInformationElementsL(CSmsUserData& aUserData, TInt aSegmentSequenceNum);
       
   265 	void InstallControlInformationElementsL(CSmsCommand& aCommand);
       
   266 	TBool AddEMSInformationElementsToMultiSegmentMessageL(CSmsEMSBufferSegmenter& aSegmenter, TUint& aCharsAdded,
       
   267 			                                              TBool aDoEncode, TSmsEncoding& aEncoding,
       
   268 			                                              RPointerArray<CEmsInformationElement>& aCorrectedFormatingIEArray,
       
   269 			                                              TUint& aCurEMSIEno, TUint& aBaseAddr);
       
   270 	TBool AddEMSInformationElementsToSingleSegmentMessageL(CSmsEMSBufferSegmenter& aSegmenter,
       
   271 			                                               TSmsEncoding aEncoding);
       
   272 	void AddControlInformationElementsToMultiSegmentMessageL(TBool aDoEncode);
       
   273 	void AddControlInformationElementsToMultiSegmentMessageL(TSmsInformationElementCategories::TInformationElementCategory aCategory, TBool aMandatoryInPDU, TBool aDoEncode);
       
   274 	void AddCurrentPDUToPDUArrayL(TBool aDoEncode);
       
   275 	TBool AddIEToUserDataL(CEmsInformationElement* aIe, TInt aCharsAlreadyAdded,TUint& aCharsAddedToCurrentPDU,CSmsEMSBufferSegmenter& aSeg);
       
   276 	TInt FillPduL(CSmsEMSBufferSegmenter& aSeg, TInt aNumChars, TSmsEncoding aEncoding);
       
   277 	TInt NumMessageEmsPDUsL();
       
   278 	void CorrectFormattingL(TUint aCharsAddedToCurrentPDU,RPointerArray<CEmsInformationElement>& aCorrectedFormatingIEArray,TUint aBaseAddr);
       
   279 	void CorrectFormattingInSinglePDUL();
       
   280 	void ResetWorkingPDUL();
       
   281 	TBool CanBeRemoved(const CEmsInformationElement& aIE, TUint aIEIndex);
       
   282 	void AddEmsUserPromptL(const CEmsUserPrompt& aEmsIE);
       
   283 	void AddEmsObjectDistributionL(const CEmsObjectDistribution& aObjectDistributionIE);
       
   284 	void UpdateUserPromptAndODIElementsStartPosition();
       
   285 	TInt AddReceivedEmsInformationElement(CEmsInformationElement* aIE);
       
   286 	TSmsStatusReportScheme FindSchemeL(const CArrayPtr<CSmsPDU>& aSmsPDUArray);
       
   287 	void InstallTPSRRInformationL(const CArrayPtr<CSmsPDU>& aSmsPDUArray, TInt aSegmentSequenceNum);
       
   288 	void EncodingTPSRRFromSchemesIntoSinglePDUL();
       
   289 	void DecodeOnlyTextL(CArrayPtr<CSmsPDU>& aSmsPDUArray,CSmsBufferBase& aBuffer);
       
   290 	void AddIncompleteMessageInfoL(TInt aStartPDU, TInt aEndPDU, TBool aLastPartialCompleteMsg);
       
   291 	void MergeAlternative7bitEncoding(TSmsEncoding aEncoding) const;
       
   292 
       
   293 private:
       
   294 	enum TSmsMessageFlags
       
   295 		{
       
   296 		ESmsFlagIsComplete=0x01,
       
   297 		ESmsFlagIsDecoded=0x02,
       
   298 
       
   299 		ESmsStorageMask=0x0C,
       
   300 		ESmsUTCOffsetSecondGranularityMask  =0x1FFFF0,//Bits needed to represent 79 * 15 * 60 seconds
       
   301 		ESmsUTCOffsetSignBit                =0x200000
       
   302 		};
       
   303 
       
   304 	enum TTimeBitMaskOffsets
       
   305 		{
       
   306 		ESecondBitOffset   =  4,
       
   307 		ESignBitOffset     = 21
       
   308 		};
       
   309 
       
   310     enum TDecodedOnSimBit
       
   311         {
       
   312         EDecodedOnSimBit = 0x80000000
       
   313         };
       
   314 
       
   315     enum TForwardToClientBit
       
   316         {
       
   317         EForwardToClientBit = 0x40000000
       
   318         };
       
   319 
       
   320 
       
   321 private:
       
   322 
       
   323 	TInt iFlags;
       
   324 	NMobileSmsStore::TMobileSmsStoreStatus iStatus;
       
   325 	TInt iLogServerId;
       
   326 	TTime iTime;
       
   327 	CSmsPDU* iSmsPDU;
       
   328 	CSmsBufferBase* iBuffer;
       
   329 	RFs& iFs;
       
   330 
       
   331 	TBool iIs16BitConcatenation;
       
   332 	RPointerArray<CEmsInformationElement>* iInformationElementArray;
       
   333 	CCnvCharacterSetConverter* iCharacterSetConverter;
       
   334 
       
   335 public:
       
   336 	CArrayFixFlat<TGsmSmsSlotEntry> iSlotArray; //< Array for slots
       
   337 /**
       
   338  *  SMS versions
       
   339  */
       
   340 	enum TSmsMessageVersion
       
   341 		{
       
   342 	/** The default value. */
       
   343 		ESmsMessageV0, 
       
   344 	/** Release 6 SMS Support */	
       
   345 		ESmsMessageV1, 
       
   346 	/** Latest version */
       
   347 		ESmsMessageV2,
       
   348 	/**	Incomplete Class0 Information Support	*/
       
   349 		ESmsMessageV3,
       
   350 		ESmsIncompleteClass0MessageV = ESmsMessageV3,
       
   351 	/** National language 7bit encoding support */
       
   352 		ESmsMessageV4
       
   353 		// for all other versions the corresponding enum values would be added i.e. ESmsMessageV5, etc. 
       
   354 		};
       
   355 
       
   356 protected:
       
   357 
       
   358 	/**
       
   359 	 *  iVersion is the version of CSmsMessage. This parameter will be
       
   360 	 *  used to identify what iAdditionalInfo points to for that particular
       
   361 	 *  version of CSmsMessage
       
   362 	 */
       
   363 	TInt iVersion;
       
   364 
       
   365 	/**
       
   366 	 *  iAdditionalInfo would point to any new added data structure.
       
   367 	 *  iVersion would identify which data structure is valid for that
       
   368 	 *   *  particular version of CSmsMessage 
       
   369 	 */
       
   370 	CSmsMessageAdditionalAttributes*  iAdditionalInfo;
       
   371 	};
       
   372 
       
   373 #include <gsmumsg.inl>
       
   374 
       
   375 #endif // !defined __GSMUMSG_H__