email/pop3andsmtpmtm/imapservermtm/inc/IMAPIO.H
changeset 25 84d9eb65b26f
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
       
     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 // CImapIO header
       
    15 // 
       
    16 //
       
    17 
       
    18 #if !defined(__IMAPIO_H__)
       
    19 #define __IMAPIO_H__
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <e32cons.h>
       
    23 #include <mentact.h>
       
    24 #include <imsk.h>
       
    25 #include <iapprefs.h>
       
    26 
       
    27 // Receive buffer size (max to read in one go). Should really be MTU related,
       
    28 // as that's what we'll get in a chunk.
       
    29 const TInt KReceiveBuffer=2048;
       
    30 
       
    31 // Transmit buffer to keep data static when sending
       
    32 const TInt KTransmitBuffer=1024;
       
    33 
       
    34 // What we return with if we find an EOL and have been asked to do a partial
       
    35 // read
       
    36 const TInt KErrFoundEOL=1;
       
    37 
       
    38 // States of async machine
       
    39 /**
       
    40 @internalComponent
       
    41 @released
       
    42 */
       
    43 enum TIOState
       
    44 	{
       
    45 	EIOStateDisconnected,
       
    46 	EIOStateConnectQueued,
       
    47 	EIOStateConnected,
       
    48 	EIOStateReadQueued,
       
    49 	EIOStateWriteQueued,
       
    50 	EIOStateDummyQueued
       
    51 	};
       
    52 
       
    53 // States of reply parser
       
    54 /**
       
    55 @internalComponent
       
    56 @released
       
    57 */
       
    58 enum TIOParserState
       
    59 	{
       
    60 	EIOStateAtomWait,
       
    61 	EIOStateInAtom,
       
    62 	EIOStateWaitLF,
       
    63 	EIOStateLiteralLength,
       
    64 	EIOStateLiteralSkip,
       
    65 	EIOStateLiteralFetch
       
    66 	};
       
    67 
       
    68 class CImapAtom : public CBase
       
    69 /**
       
    70 @internalComponent
       
    71 @released
       
    72 */
       
    73 	{
       
    74 public:
       
    75 	CImapAtom();
       
    76 	~CImapAtom();
       
    77 
       
    78 	void		Set(const TDesC8& aAtom);
       
    79 	void		AddChild(CImapAtom *aNewChild);
       
    80 	void		AddNext(CImapAtom *aNewNext);
       
    81 
       
    82 	// Get child/next pointers
       
    83 	CImapAtom*	Child();
       
    84 	CImapAtom*	Next();
       
    85 
       
    86 	// As above, but with leave if null
       
    87 	CImapAtom*	ToChildL();
       
    88 	CImapAtom*	ToNextL();
       
    89 
       
    90 	TPtrC8		Atom();
       
    91 	TBool		Compare(const TDesC8& aValue);
       
    92 	TBool       CompareTail(const TDesC8& aValue);
       
    93 	TInt		Value(TUint& aValue);
       
    94 	TInt		Value(TInt& aValue);
       
    95 	TInt		Value(TInt32& aValue);
       
    96 	void		FixupL(const HBufC8 *aNewBuffer, const TText8 *aOldBuffer);
       
    97 	TPtrC8		AtomNoAngleBrackets();
       
    98 
       
    99 private:
       
   100 	TPtrC8		iAtom;
       
   101 	CImapAtom*	iChild;
       
   102 	CImapAtom*	iNext;
       
   103 	};
       
   104 
       
   105 
       
   106 class CImapIO : public CMsgActive
       
   107 /**
       
   108 @internalComponent
       
   109 @released
       
   110 */
       
   111 	{
       
   112 public:
       
   113 	~CImapIO();
       
   114 
       
   115 	static CImapIO*	NewLC(TInt aId);
       
   116 	static CImapIO*	NewL(TInt aId);
       
   117 
       
   118 	// Queue a connect
       
   119 	void ConnectL(TRequestStatus& aStatus, const TDesC& aHost, const TUint aPort, const CImIAPPreferences& aPrefs, TBool aSSLWrappedSocket);
       
   120 
       
   121 	// Queue a line read
       
   122 	TInt GetReply(TRequestStatus& aStatus);
       
   123 	TInt GetReply(TRequestStatus& aStatus, const TInt aFetchSize, const TBool aPartialReturn);
       
   124 
       
   125 	// Queue a line write
       
   126 	TInt Send(TRequestStatus& aStatus, TRefByValue<const TDesC8> aFmt,...);
       
   127 	void SendL(TRequestStatus& aStatus, TRefByValue<const TDesC8> aFmt,...);
       
   128 	void SendWithTimeoutL(TRequestStatus& aStatus, TInt aTimeout, TRefByValue<const TDesC8> aFmt,...);
       
   129 
       
   130 	// Logging
       
   131 	void PerformLogging(TBool aLogging);
       
   132 
       
   133 	// Queue a dummy read for connection status notification
       
   134 	void QueueDummy(TRequestStatus& aStatus);
       
   135 
       
   136 	// Get the root atom of the parse tree
       
   137 	CImapAtom*	RootAtom();
       
   138 
       
   139 	// Get bytes in/out totals
       
   140 	TInt RXbytes(const TBool aReset);
       
   141 	TInt TXbytes(const TBool aReset);
       
   142 
       
   143 	// Disconnect
       
   144 	void Disconnect();
       
   145 
       
   146 	// Security
       
   147 	void SetTLSResponseL();
       
   148 	
       
   149 	// From IMSK
       
   150 	void LogText(const TDesC8& aString);	
       
   151 	void LogText(TRefByValue<const TDesC8> aFmt,...);
       
   152 	
       
   153 /**
       
   154 	@fn				TInt GetIAPValue(TUint32& aIap)
       
   155 	Intended Usage	:	Gets the value of the currently connecting/connected IAP
       
   156 	@param			aIap will be value of the currently connecting/connected IAP or KErrNotFound if an error occurs 
       
   157 	@return			KErrNone if succesful, KErrNotFound is the session does not exist or a system-wide error code.
       
   158 
       
   159 	*/
       
   160 	TInt GetIAPValue(TUint32& aIap);
       
   161 
       
   162 /**
       
   163 	@fn				GetRConnectionName()
       
   164 	Intended Usage	:	On return, the unique name of the RConnection.
       
   165 	@since			9.1
       
   166 	@return			KErrNone if succesful, or another of the system-wide error codes. 
       
   167 	*/	
       
   168 	TInt GetRConnectionName(TName &aName);
       
   169 	
       
   170 /**
       
   171 	@fn				GetLastSocketActivityTimeout(TUint32& aTimeout)
       
   172 	Intended Usage	:	Returns the last socket activity timeout value
       
   173 	@since			9.1
       
   174 	@param			aTimeout is a return argument containing the timeout if it was found
       
   175 	@post				aTimeout will be filled with the timeout value
       
   176 	@return			Returns KErrNone, KErrNotFound or KErrBadHandle
       
   177 	*/
       
   178 	TInt GetLastSocketActivityTimeout(TUint32& aTimeout);
       
   179 
       
   180 /**
       
   181 	@fn				TInt GetConnectionStage()
       
   182 	Intended Usage	:	Gets the stage of the connection process as defined in nifvar.h and csdprog.h
       
   183 	@since			7.0s
       
   184 	@return         The current connection stage, KErrNotFound is the session does not exist or a system-wide error code.
       
   185 
       
   186 	*/
       
   187 	TInt GetConnectionStage();
       
   188 	
       
   189 /**
       
   190 	@fn				SetPrimaryTextServerSession(CImTextServerSession* aPrimaryTextServerSession)
       
   191 	Intended Usage	:	Sets the local primaryTextSeverSession from PrimarySession's TextServerSession.
       
   192 						Going to be use on the secondary session
       
   193 	@since			9.2
       
   194 	@param			aPrimaryTextServerSession is to store the primary session's TextServerSession
       
   195 	*/	
       
   196 	void SetPrimaryTextServerSession(CImTextServerSession* aPrimaryTextServerSession);
       
   197 
       
   198 /**
       
   199 	@fn				GetTextServerSession()
       
   200 	Intended Usage	:	Returns CImTextServerSession
       
   201 	@since			9.2
       
   202 	@return			CImTextServerSession 
       
   203 	*/	
       
   204 	CImTextServerSession* GetTextServerSession();
       
   205 
       
   206 private:
       
   207 	CImapIO(TInt aId);
       
   208 	void ConstructL();
       
   209 	void DoComplete(TInt& /*aStatus*/);
       
   210 	void DoRunL();
       
   211 	void DoCancel();
       
   212 	void ProcessBufferL();
       
   213 	void QueueRead();
       
   214 	void BufferAppendL(const TChar aChar);
       
   215 
       
   216 	void PushL(CImapAtom *aItem);
       
   217 	CImapAtom* PopL();
       
   218 
       
   219 	void AddAtomL();
       
   220 	void AddAtomL(const TInt);
       
   221 	TInt Send(TRequestStatus& aStatus, const TDesC8& aCommand);
       
   222 	TInt SendWithTimeout(TRequestStatus& aStatus, TInt aTimeout, const TDesC8& aCommand);
       
   223 
       
   224 private:
       
   225 	TIOState				iState;
       
   226 	TIOParserState			iParserState;
       
   227 	TBool					iParserQuoted;
       
   228 	TBool					iGotEscape;
       
   229 	TInt					iLineStatus;
       
   230 	TInt					iLiteralSkip;
       
   231 	TInt					iLiteralLength;
       
   232 	TInt					iBytesRead;
       
   233 	TInt					iBytesToRead;
       
   234 	TBool					iReturnPartialLine;
       
   235 
       
   236 	HBufC8*					iBuffer;
       
   237 	TInt					iBufferSize;
       
   238 	TBuf8<KReceiveBuffer>	iReceive;
       
   239 	TBuf8<KTransmitBuffer>	iTransmit;
       
   240 	TInt					iLen;
       
   241 	TBuf8<1>				iDummyBuffer;
       
   242 
       
   243 	CImapAtom*				iRootAtom;
       
   244 	CImapAtom*				iAtom;
       
   245 	TPtrC8					iCurrentAtom;
       
   246 	TInt					iAtomStart;
       
   247 
       
   248 	CArrayPtrFlat<CImapAtom>	iAtomStack;
       
   249 	TBool					iNextIsChild;
       
   250 
       
   251 	// Byte I/O totals
       
   252 	TInt					iTXbytes;
       
   253 	TInt					iRXbytes;
       
   254 
       
   255 	// Actual connection
       
   256 	CImTextServerSession*	iSession;
       
   257 
       
   258 	// Extra logging
       
   259 	CImLog*					iImapLog;
       
   260 
       
   261 	// Atom array
       
   262 	RPointerArray<CImapAtom> iAtomArray;
       
   263 
       
   264 	TInt					iID;
       
   265 	
       
   266 	// Take ownership of primary session's Textserversession object
       
   267 	// Only going to be set on the secondary session 
       
   268 	CImTextServerSession* 	iPrimaryTextServerSession;
       
   269 	
       
   270 	};
       
   271 
       
   272 #endif