email/imap4mtm/imapsession/inc/cimapatomparser.h
changeset 0 72b543305e3a
child 65 d8ac8e5e4721
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 1998-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 // CImapAtomParser header
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __CIMAPATOMPARSER_H__
       
    19 #define __CIMAPATOMPARSER_H__
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 // forward declaration
       
    24 class CImapAtom;
       
    25 
       
    26 /**
       
    27 This class takes an IMAP response string and parses it into a tree of atoms.
       
    28 Whenever an open bracket is detected, a subtree is formed until the matching 
       
    29 close bracket is found.
       
    30 Quoted literals are treated as a single atom.
       
    31 The parser will stop parsing when the a close bracket is found to match the very first open bracket.
       
    32 The remaining unparsed data can be accessed via UnparsedData.
       
    33 @internalComponent
       
    34 @prototype
       
    35 */
       
    36 class CImapAtomParser : public CBase
       
    37 	{
       
    38 public:
       
    39 	/**
       
    40 	States of reply parser
       
    41 	
       
    42 	@internalComponent
       
    43 	@prototype
       
    44 	*/
       
    45 	enum TParserState
       
    46 		{
       
    47 		EStateAtomWait,
       
    48 		EStateInAtom,
       
    49 		EStateLiteralLength,
       
    50 		EStateLiteralSkip,
       
    51 		EStateLiteralFetch,
       
    52 		EStateParseComplete,
       
    53 		};
       
    54 
       
    55 	~CImapAtomParser();
       
    56 
       
    57 	static CImapAtomParser*	NewL(TBool aAllowParseAtTopLevel, TInt aLogId);
       
    58 
       
    59 	TBool ProcessLineL(const TDesC8& aLine);
       
    60 	void ProcessLiteralBlockL(const TDesC8& aLiteralBlock);
       
    61 
       
    62 	// Get the root atom of the parse tree
       
    63 	CImapAtom*	RootAtom();
       
    64 	
       
    65 	const TPtrC8& UnparsedData();
       
    66 
       
    67 	HBufC8*	DetachBuffer();
       
    68 
       
    69 private:
       
    70 	CImapAtomParser(TBool aAllowParseAtTopLevel, TInt aLogId);
       
    71 	void ConstructL();
       
    72 
       
    73 	void BufferAppendL(const TChar aChar);
       
    74 
       
    75 	void PushL(CImapAtom* aItem);
       
    76 	CImapAtom* PopL();
       
    77 
       
    78 	void AddAtomL();
       
    79 private:
       
    80 	/**
       
    81 	If you have a string such as "aaaa (bbbb (xx yy)) cccc".
       
    82 	With this set to ETrue, then the whole of "aaaa (bbbb (xx yy)) cccc" will be parsed.
       
    83 	But when set to EFalse, only "aaaa (bbbb (xx yy))" will be parsed as the last matching bracket has been found.
       
    84 	*/
       
    85 	TBool					iAllowParseAtTopLevel;
       
    86 
       
    87 	TParserState			iParserState;
       
    88 	TBool					iParserQuoted;
       
    89 	TBool					iGotEscape;
       
    90 	TInt					iLiteralLength;
       
    91 	TInt 					iLiteralSkip;
       
    92 
       
    93 	/**
       
    94 	A heap buffer that stores all the data pointed to by the CImapAtom objects.
       
    95 	*/
       
    96 	HBufC8*					iBuffer;
       
    97 	TInt					iBufferSize; // can we use iBuffer->MaxLength() here?
       
    98 
       
    99 	/**
       
   100 	The root atom.  Owned.
       
   101 	*/
       
   102 	CImapAtom*				iRootAtom;
       
   103 	/**
       
   104 	The atom that is currently being procesed.  Not owned.
       
   105 	*/
       
   106 	CImapAtom*				iAtom;
       
   107 	/**
       
   108 	Index of the first character of the atom currently being processed
       
   109 	*/
       
   110 	TInt					iAtomStart;
       
   111 
       
   112 	/**	
       
   113 	Atom array owns ALL the atom objects EXCEPT the root atom.
       
   114 	*/	
       
   115 	RPointerArray<CImapAtom> iAtomArray; 
       
   116 	
       
   117 	/**
       
   118 	A stack that is used to navigate back up an atom tree as it is being built.
       
   119 	This arrat does not own the objects that it points at.
       
   120 	*/
       
   121 	RPointerArray<CImapAtom> iAtomStack;
       
   122 	/**
       
   123 	Whether the next atom object to be constructed should be added to the tree as
       
   124 	a child of the current atom (ETrue) or as its sibling (EFalse).
       
   125 	*/
       
   126 	TBool					iNextIsChild;
       
   127 	
       
   128 	/**
       
   129 	Points at the unparsed portion of the last line to be processed.
       
   130 	This pointer descriptor is only valid while the descriptor it points at is valid
       
   131 	This pointer descriptor will only be set after ProcessLineL() has returned
       
   132 	EFalse to indicate that no more data is expected.
       
   133 	*/
       
   134 	TPtrC8					iUnparsedData;
       
   135 	
       
   136 	/**
       
   137 	Log id of owning session
       
   138 	*/
       
   139 	TInt iLogId;
       
   140 	};
       
   141 
       
   142 #endif // __CIMAPATOMPARSER_H__