williamr@2: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // 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 williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // BSP.H (Base Script Parser) williamr@2: // Abstract class for different Parsers. williamr@2: // williamr@2: // williamr@2: williamr@2: williamr@2: #if !defined(__BSP_H__) williamr@2: #define __BSP_H__ williamr@2: williamr@2: #if !defined(__MTCLREG_H__) williamr@2: #include williamr@2: #endif williamr@2: williamr@2: #if !defined(__MTCLBASE_H__) williamr@2: #include williamr@2: #endif williamr@2: williamr@2: #include williamr@2: #if !defined(__S32STRM_H__) williamr@2: #include williamr@2: #endif williamr@2: williamr@2: #include williamr@2: // CRichText etc. includes williamr@2: #include williamr@2: #include williamr@2: williamr@2: #include williamr@2: williamr@2: williamr@2: williamr@2: // Symbols: williamr@2: /** Space character. */ williamr@2: #define KCharSpace ' ' williamr@2: /** Tab character. */ williamr@2: #define KCharTab '\t' williamr@2: /** Line feed character. */ williamr@2: #define KCharLineFeed '\n' williamr@2: williamr@2: williamr@2: // Define some generic error codes: williamr@2: /** BIO error code base. */ williamr@2: const TInt KBspBaseError = (-500); williamr@2: williamr@2: /** Invalid BIO message error code. */ williamr@2: const TInt KBspInvalidMessage = (KBspBaseError); williamr@2: /** Invalid smart message token error code. */ williamr@2: const TInt KBspSmartMessageInvalidToken = (KBspBaseError-1); williamr@2: /** No smart message parser defined error code. */ williamr@2: const TInt KBspSmartMessageNoParserDefined = (KBspBaseError-2); williamr@2: williamr@2: // Parsed field class for use by parsers. williamr@2: class CParsedField : public CBase williamr@2: /** Represents a single token-value pair for a given field in a BIO/smart message williamr@2: grammar. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C CParsedField(); williamr@2: IMPORT_C ~CParsedField(); williamr@2: williamr@2: IMPORT_C TPtrC FieldName() const; williamr@2: IMPORT_C void SetFieldNameL( const TDesC& aFieldName); williamr@2: IMPORT_C TPtrC FieldValue() const; williamr@2: IMPORT_C void SetFieldValueL( const TDesC& aFieldValue); williamr@2: IMPORT_C TBool MandatoryField() const; williamr@2: IMPORT_C void SetMandatoryField(TBool aMandatoryField); williamr@2: williamr@2: IMPORT_C void InternalizeL(RReadStream& aStream); williamr@2: IMPORT_C void ExternalizeL(RWriteStream& aStream) const; williamr@2: private: williamr@2: void Reset(); williamr@2: private: williamr@2: HBufC* iFieldName; williamr@2: HBufC* iFieldValue; williamr@2: TBool iMandatoryField; williamr@2: }; williamr@2: williamr@2: // Forward declarations: williamr@2: class CMsvServerEntry; williamr@2: class CMsvEntry; williamr@2: class CRegisteredParserDll; williamr@2: class RMsvReadStream; williamr@2: class RMsvWriteStream; williamr@2: class CMsvStore; williamr@2: class CSmsMessage; williamr@2: williamr@2: williamr@2: williamr@2: /** Base class for BIO message parsers V2. williamr@2: williamr@2: Concrete derived classes are implemented in parser DLL's to parse particular williamr@2: types of BIO message. williamr@2: williamr@2: On receiving an appropriate command (see TBioOperation), the BIO server MTM williamr@2: loads the appropriate parser and passes the message body to it for interpretation. williamr@2: In fact, the parser interface expects the parser to divide its operation into williamr@2: two stages: williamr@2: williamr@2: 1. parsing: which involves extracting information from the raw message body and williamr@2: storing it in a structured format. The parsing stage can also alter the message williamr@2: body, and create files in the directory associated with the message (e.g. williamr@2: parsing a ring tones message will generate a ring tone file). williamr@2: williamr@2: 2. processing: which involves using the extracted information to achieve the williamr@2: purpose of the BIO message (e.g. setting some phone configuration setttings). williamr@2: williamr@2: This separation allows, for example, a UI to display the parsed information williamr@2: to the user for confirmation, before it is acted upon. For some parsers, however, williamr@2: this two stage division is not sensible, in which case they implement only williamr@2: the first. williamr@2: williamr@2: The base class provides a pointer iSettings to reference the raw message data, williamr@2: and an array of token-value pairs, iParsedFieldArray, for storing parsed information williamr@2: (if this is appropriate). williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class CBaseScriptParser2: public CActive williamr@2: { williamr@2: public: williamr@2: IMPORT_C CBaseScriptParser2(CRegisteredParserDll& aRegisteredParserDll, CMsvEntry& aEntry, RFs& aFs); williamr@2: IMPORT_C ~CBaseScriptParser2(); williamr@2: williamr@2: /** Called by the BIO server MTM to asynchronously parse message body data. williamr@2: williamr@2: When parsing is complete, the function should indicate this by setting the williamr@2: message's index field iMtmData3 to 1. williamr@2: williamr@2: The function should leave if the buffer cannot be parsed successfully. williamr@2: williamr@2: @param aStatus Asynchronous status word williamr@2: @param aSms Buffer to parse */ williamr@2: virtual void ParseL(TRequestStatus& aStatus, const TDesC& aSms)=0; //parses sms data into CParsedField williamr@2: /** Called by the BIO server MTM to asynchronously process the parsed data. williamr@2: williamr@2: The function takes appropriate parser-specific action on the results of a williamr@2: previous call to ParseL(). williamr@2: williamr@2: When processing is complete, the function should indicate this by setting williamr@2: the message's index field iMtmData3 to 2. williamr@2: williamr@2: The function should leave if processing is not successful. williamr@2: williamr@2: @param aStatus Asynchronous status word */ williamr@2: virtual void ProcessL(TRequestStatus& aStatus)=0; //stores parsed data into streams and data base williamr@2: williamr@2: IMPORT_C TUid ParserUid(); williamr@2: IMPORT_C void RestoreL(CMsvStore& aMessageStore); williamr@2: IMPORT_C void StoreL(CMsvStore& aMsvStore) const; williamr@2: IMPORT_C void RestoreL(const TFileName& aFileName); williamr@2: IMPORT_C void StoreL(const TFileName& aFileName) const; williamr@2: IMPORT_C void ResetL(); williamr@2: williamr@2: protected: williamr@2: // Parsing: williamr@2: IMPORT_C void UnfoldMessageL(); williamr@2: williamr@2: // Streaming operations: williamr@2: void InternalizeL(RMsvReadStream& aStream); williamr@2: void ExternalizeL(RMsvWriteStream& aStream) const; williamr@2: williamr@2: protected: williamr@2: /** Object that loaded the parser. It contains a reference counter of the use of williamr@2: the parser. */ williamr@2: CRegisteredParserDll& iRegisteredParserDll; williamr@2: /** The message entry the parser should parse. */ williamr@2: CMsvEntry& iEntry; williamr@2: /** Connected file server handle. */ williamr@2: RFs& iFs; williamr@2: williamr@2: /** Lexer intended for Smart Message use. williamr@2: williamr@2: This is not used by the base class. */ williamr@2: TLex iSms; williamr@2: /** Array of token-value pairs. williamr@2: williamr@2: Derived classes can use this for storing parsed information (if this is appropriate). */ williamr@2: CArrayPtrSeg* iParsedFieldArray; williamr@2: williamr@2: /** Flag intended for Smart Message use. williamr@2: williamr@2: This is not used by the base class. */ williamr@2: TBool iSmsParsed; williamr@2: /** ID of iEntry. */ williamr@2: TMsvId iEntryId; williamr@2: williamr@2: /** Pointer to message data. williamr@2: williamr@2: This is not set by the base class. */ williamr@2: HBufC* iSettings; williamr@2: /** Pointer to SMS data (intended for Smart Message use). williamr@2: williamr@2: This is not set by the base class. */ williamr@2: HBufC* iSmsBuf; // Local copy of buffer passed to ParseL() williamr@2: /** Temporary pointer used by RestoreL(). */ williamr@2: HBufC8* iReadBuffer; // used to restore data from file williamr@2: }; williamr@2: williamr@2: williamr@2: /** BIO data location flag values. williamr@2: williamr@2: @see TMsvBIOEntry */ williamr@2: enum TMsvBIODataLocation williamr@2: { williamr@2: /** Unknown. */ williamr@2: EUnknown, williamr@2: /** Parser wrote data into the body text. */ williamr@2: EBodyText, // parser wrote data back into richText williamr@2: /** Parser wrote data into the parsed fields data stream. */ williamr@2: EBIODataStream, // parser wrote data into KUIDMsvBioStream williamr@2: /** Parser wrote data into an attachment file. */ williamr@2: EFile // parser wrote data into attachment file williamr@2: }; williamr@2: williamr@2: williamr@2: /** Bearer Independent Object entry. williamr@2: Specialises the TMsvEntry message entry class to store additional BIO message-specific williamr@2: information. williamr@2: @internalTechnology williamr@2: @released williamr@2: */ williamr@2: class TMsvBIOEntry : public TMsvEntry williamr@2: { williamr@2: public: williamr@2: /** Constructor. */ williamr@2: TMsvBIOEntry() : TMsvEntry() {}; williamr@2: void SetBIOParserUid(const TUid aId); williamr@2: const TUid BIOParserUid() const; williamr@2: void SetLocationOfData(const TMsvBIODataLocation aLocation); williamr@2: const TMsvBIODataLocation LocationOfData() const; williamr@2: williamr@2: private: williamr@2: TMsvBIODataLocation iLocationOfData; williamr@2: }; williamr@2: williamr@2: #include williamr@2: williamr@2: #endif