|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 #ifndef __CIMAPSESSIONMANAGER_H__ |
|
17 #define __CIMAPSESSIONMANAGER_H__ |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <es_sock.h> |
|
21 #include <msvstd.h> |
|
22 #include <mentact.h> |
|
23 #include "msocketconnectobserver.h" |
|
24 #include "moutputstreamobserver.h" |
|
25 #include "moutputstreamsecureobserver.h" |
|
26 #include "minputstreamobserver.h" |
|
27 #include "cimaplistfolderinfo.h" |
|
28 #if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT) |
|
29 #include "cimapauthhelpers.h" |
|
30 #endif |
|
31 |
|
32 |
|
33 // Forward Declarations |
|
34 class CImapSession; |
|
35 class CImapSettings; |
|
36 class CImapMailStore; |
|
37 class CTransportManager; |
|
38 class MInputStream; |
|
39 class MOutputStream; |
|
40 class TImap4GenericProgress; |
|
41 class CImapListFolderInfo; |
|
42 class CImConnect; |
|
43 class MSocketConnector; |
|
44 #if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT) |
|
45 class CImapCapabilityInfo; |
|
46 class CImapAuthMechanismHelper; |
|
47 #endif |
|
48 |
|
49 /** |
|
50 Provides a mechanism for creating connected, logged in CImapSession objects, |
|
51 and for disconnecting them. |
|
52 The objects are created on behalf of the requesting class, which owns the |
|
53 created CImapSession objects immediately upon creation. |
|
54 @internalTechnology |
|
55 @prototype |
|
56 */ |
|
57 class CImapSessionManager : public CMsgActive, |
|
58 public MSocketConnectObserver, |
|
59 public MOutputStreamObserver, |
|
60 public MOutputStreamSecureObserver, |
|
61 public MInputStreamObserver |
|
62 { |
|
63 public: |
|
64 IMPORT_C static CImapSessionManager* NewL(CImapSettings& aImapSettings, CImapMailStore& aImapMailStore); |
|
65 ~CImapSessionManager(); |
|
66 |
|
67 // Get a connected, logged in session. The passed session pointer |
|
68 // should not be used unless the routine completes with a status of |
|
69 // KErrNone. |
|
70 IMPORT_C void GetSessionL(TRequestStatus& aStatus, CImapSession*& aSession); |
|
71 // Logout and disconnect a list of sessions |
|
72 IMPORT_C void Disconnect(TRequestStatus& aStatus, const RPointerArray<CImapSession>& sessionList); |
|
73 // Immediately disconnect a list of sessions |
|
74 IMPORT_C void Disconnect(const RPointerArray<CImapSession>& sessionList); |
|
75 // Immediately disconnect a single session |
|
76 IMPORT_C void Disconnect(const CImapSession& aSession); |
|
77 // Get LastSocketActivityTimeout value from the connection |
|
78 IMPORT_C TUint32 LastSocketActivityTimeout(); |
|
79 // Get progress information for current operation |
|
80 IMPORT_C void Progress(TImap4GenericProgress& aProgress); |
|
81 // Identifies if an RConnection is available |
|
82 IMPORT_C TBool HasConnection(); |
|
83 // Get the RConnection used by all the sessions |
|
84 IMPORT_C RConnection& GetConnectionL(); |
|
85 // Gets the access point ID in use for the connection to the server |
|
86 IMPORT_C TInt GetAccessPointIdForConnection(TUint32& aAccessPointId) const; |
|
87 // Close the current network connection |
|
88 IMPORT_C void CloseNetworkConnection(); |
|
89 |
|
90 private: |
|
91 // Construction routines |
|
92 CImapSessionManager(CImapSettings& aImapSettings, CImapMailStore& aImapMailStore); |
|
93 void ConstructL(); |
|
94 |
|
95 // from MSocketConnectObserver |
|
96 virtual void ConnectionMadeL(MInputStream& aInputStream, MOutputStream& aOutputStream); |
|
97 virtual TInt HandleConnectError(TInt aError); |
|
98 |
|
99 // from MOutputStreamObserver |
|
100 virtual void SendDataCnf(); |
|
101 virtual void OutputStreamCloseInd(TInt aError); |
|
102 |
|
103 // from MOutputStreamSecureObserver |
|
104 virtual void SecureClientCnf(TInt aError); |
|
105 |
|
106 // from MInputStreamObserver |
|
107 virtual void ReceivedDataIndL(const TDesC8& aBuffer); |
|
108 virtual void SecureServerCnf(); |
|
109 virtual void InputStreamCloseInd(TInt aError); |
|
110 |
|
111 // from CMsgActive |
|
112 virtual void DoRunL(); |
|
113 virtual void DoCancel(); |
|
114 virtual void DoComplete(TInt& aStatus); |
|
115 |
|
116 // State handlers for state machine |
|
117 void ProcessNetworkConnectionCreatedL(); |
|
118 void ProcessSocketConnectedL(); |
|
119 void ProcessUpgradedSSLWrappedSocketL(); |
|
120 void ProcessGreetingResponseL(); |
|
121 void ProcessCapabilityResponseL(); |
|
122 void ProcessStartTLSResponse(); |
|
123 void ProcessUpgradedTLSSocketL(); |
|
124 void ProcessSecureCapabilityResponseL(); |
|
125 void ProcessLoginResponseL(); |
|
126 void ProcessSeparatorResponseL(); |
|
127 void ProcessLogoutResponse(); |
|
128 void ProcessSocketDisconnected(); |
|
129 void CreateSecureSocket(); |
|
130 void StartSessionL(); |
|
131 void CreateNetworkConnectionL(); |
|
132 void CreateSocketL(); |
|
133 void SendLoginL(); |
|
134 void GetHierarchySeparatorL(); |
|
135 void DisconnectFirstSessionInList(); |
|
136 void DisconnectSocket(); |
|
137 void ImmediateDisconnect(); |
|
138 void CloseSessionStreams(CImapSession* aSession); |
|
139 TInt GetConnectionStage(); |
|
140 void ConvertError(TInt& aError); |
|
141 void CompleteSelf(TInt aError); |
|
142 TInt LogId(); |
|
143 #if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT) |
|
144 void ProcessAuthenticateResponseL(); |
|
145 void SelectAuthExtensionProfileL(const CImapCapabilityInfo& aCapabilityInfo); |
|
146 void SendAuthenticateL(CImapAuthMechanismHelper::TImapAuthProfileFlag aCurrentAuthProfile); |
|
147 #endif |
|
148 |
|
149 private: |
|
150 |
|
151 /** |
|
152 IMAP Session Manager States |
|
153 @internalComponent |
|
154 @prototype |
|
155 */ |
|
156 enum TImapSessionManagerState |
|
157 { |
|
158 EStateIdle, |
|
159 EStateCreatingNetworkConnection, |
|
160 EStateConnectingSocket, |
|
161 EStateGettingLastSocketActivityTimeout, |
|
162 EStateUpgradingSSLWrappedSocket, |
|
163 EStateGreetingWait, |
|
164 EStateCapabilityWait, |
|
165 EStateStartTLSWait, |
|
166 EStateUpgradingTLSSocket, |
|
167 EStateSecureCapabilityWait, |
|
168 EStateLoginWait, |
|
169 EStateSeparatorWait, |
|
170 EStateLogoutWait, |
|
171 #if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT) |
|
172 EStateAuthenticateWait, |
|
173 #endif |
|
174 EStateDisconnectingSocket |
|
175 |
|
176 }; |
|
177 |
|
178 // Session Manager State |
|
179 TImapSessionManagerState iState; |
|
180 |
|
181 // Progress state |
|
182 TImap4GenericProgress::TImap4GenericProgressState iProgressState; |
|
183 |
|
184 // Service settings, passed on construction: |
|
185 CImapSettings& iImapSettings; |
|
186 |
|
187 // Mail Store, passed on construction: |
|
188 CImapMailStore& iImapMailStore; |
|
189 |
|
190 // created on construction: |
|
191 CTransportManager* iTransportManager; |
|
192 |
|
193 // The Imap session being created |
|
194 CImapSession* iImapSession; |
|
195 |
|
196 // Pointer to the session store of the session create caller. |
|
197 // This is updated to point to the newly created session, after the |
|
198 // session has been fully created. |
|
199 CImapSession** iStoreSession; |
|
200 |
|
201 // Host address |
|
202 HBufC8* iHostAddr8; |
|
203 |
|
204 // Session input and output streams |
|
205 MInputStream* iInputStream; |
|
206 MOutputStream* iOutputStream; |
|
207 |
|
208 // List of sessions to disconnect. Sessions to be disconnected |
|
209 // are not owned by session manager so are not deleted. |
|
210 RPointerArray<CImapSession> iDisconnectList; |
|
211 |
|
212 // Socket server |
|
213 RSocketServ iSocketServ; |
|
214 // Handles RConnection used by sockets |
|
215 CImConnect* iImConnect; |
|
216 // Flag to indicate if network connection is created yet |
|
217 TBool iCreatedNetworkConnection; |
|
218 |
|
219 // Stores result of calling list command to get separator value |
|
220 RArrayImapListFolderInfo iSeparatorFolderList; |
|
221 |
|
222 // LastSocketActivityTimeout value read from CImConnect |
|
223 TUint32 iLastSocketActivityTimeout; |
|
224 |
|
225 // Socket connector used to create connection. |
|
226 // Not owned by this class |
|
227 MSocketConnector* iSocketConnector; |
|
228 |
|
229 // Flag to indicate that we have just completed ourself. |
|
230 // We use callbacks from the transport handler to receive error |
|
231 // notifications and then self complete with those error codes. As it is |
|
232 // possible to receive more than one callback at a time, we use this flag |
|
233 // to ensure we don't try to self complete more than once. |
|
234 TBool iCompletedSelf; |
|
235 |
|
236 // Flag to indicate if there was an error while upgrading the socket to SSL/TLS. |
|
237 TBool iErrorUpgradingSSLSocket; |
|
238 |
|
239 #if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT) |
|
240 CImapAuthMechanismHelper::TImapAuthProfileFlag iCurrentAuthProfile; |
|
241 #endif |
|
242 }; |
|
243 |
|
244 #endif // __CIMAPSESSIONMANAGER_H__ |