|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Implementation of class CHttpWapSession. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <HttpFilterCommonStringsExt.h> |
|
24 #include "HttpWapSession.h" |
|
25 #include "CodError.h" |
|
26 #include "CodLogger.h" |
|
27 #include "CodPanic.h" |
|
28 |
|
29 /// WSP protocol name. |
|
30 _LIT8( KCodWspProtocol, "WSP/WSP" ); |
|
31 /// Default WAP server port. |
|
32 const TInt KCodWspRemotePort = 9201; |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 // --------------------------------------------------------- |
|
37 // CHttpWapSession::NewL() |
|
38 // --------------------------------------------------------- |
|
39 // |
|
40 CHttpWapSession* CHttpWapSession::NewL( const TDesC8& aGateway ) |
|
41 { |
|
42 CHttpWapSession* sess = new( ELeave ) CHttpWapSession(); |
|
43 CleanupStack::PushL( sess ); |
|
44 sess->ConstructL( aGateway ); |
|
45 CleanupStack::Pop( sess ); |
|
46 return sess; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // CHttpWapSession::~CHttpWapSession() |
|
51 // --------------------------------------------------------- |
|
52 // |
|
53 CHttpWapSession::~CHttpWapSession() |
|
54 { |
|
55 CLOG(( EWapConn, 2, _L("-> CHttpWapSession::~CHttpWapSession") )); |
|
56 Disconnect(); |
|
57 if ( iGatewayOpen ) |
|
58 { |
|
59 iGateway.Close(); |
|
60 } |
|
61 iSess.Close(); |
|
62 delete iWait; |
|
63 CLOG(( EWapConn, 2, _L("<- CHttpWapSession::~CHttpWapSession") )); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------- |
|
67 // CHttpWapSession::ConnectL() |
|
68 // --------------------------------------------------------- |
|
69 // |
|
70 void CHttpWapSession::ConnectL( TRequestStatus* aStatus ) |
|
71 { |
|
72 CLOG(( EWapConn, 2, _L("-> CHttpWapSession::ConnectL") )); |
|
73 CLOG(( EWapConn, 3, _L8(" iGateway <%S> port(%d)"),\ |
|
74 &(iGateway.DesC()), KCodWspRemotePort )); |
|
75 |
|
76 // Misuse asserts. |
|
77 __ASSERT_ALWAYS( aStatus, CodPanic( ECodInvalidArguments ) ); |
|
78 __ASSERT_ALWAYS( iState == EInit, CodPanic( ECodOffState ) ); |
|
79 // Internal asserts. |
|
80 __ASSERT_DEBUG( !iParentStatus, CodPanic( ECodInternal ) ); |
|
81 |
|
82 RHTTPConnectionInfo connInfo = iSess.ConnectionInfo(); |
|
83 connInfo.SetPropertyL |
|
84 ( StringF( HTTP::EWspProxyAddress ), THTTPHdrVal( iGateway ) ); |
|
85 connInfo.SetPropertyL |
|
86 ( StringF( HTTP::EWspRemotePort ), THTTPHdrVal( KCodWspRemotePort ) ); |
|
87 // Connect to WAP gateway. |
|
88 iSess.SetSessionEventCallback( this ); |
|
89 iSess.ConnectL(); |
|
90 |
|
91 iState = EConnecting; |
|
92 |
|
93 iParentStatus = aStatus; |
|
94 *iParentStatus = KRequestPending; |
|
95 |
|
96 CLOG(( EWapConn, 2, _L("<- CHttpWapSession::ConnectL") )); |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CHttpWapSession::Disconnect() |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 void CHttpWapSession::Disconnect() |
|
104 { |
|
105 CLOG(( EWapConn, 2, _L("-> CHttpWapSession::Disconnect iState(%d)"), \ |
|
106 iState )); |
|
107 switch ( iState ) |
|
108 { |
|
109 case EConnecting: |
|
110 case EConnected: |
|
111 { |
|
112 TRAPD( err, iSess.DisconnectL() ); |
|
113 if ( err ) |
|
114 { |
|
115 // Nothing we can do about this failure! |
|
116 CLOG(( EConn, 3, _L(" failed(%d)"), err )); |
|
117 } |
|
118 else |
|
119 { |
|
120 iState = EDisconnecting; |
|
121 CLOG(( EConn, 3, _L(" starting wait") )); |
|
122 iWait->Start(); |
|
123 } |
|
124 break; |
|
125 } |
|
126 |
|
127 case EInit: |
|
128 case EDisconnecting: |
|
129 default: |
|
130 { |
|
131 CLOG(( EConn, 3, _L(" nothing to do") )); |
|
132 // EInit state: no need to do anything. |
|
133 // EDisconnecting: we can't do anything. |
|
134 break; |
|
135 } |
|
136 } |
|
137 CLOG(( EWapConn, 2, _L("<- CHttpWapSession::Disconnect") )); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------- |
|
141 // CHttpWapSession::CHttpWapSession() |
|
142 // --------------------------------------------------------- |
|
143 // |
|
144 CHttpWapSession::CHttpWapSession() |
|
145 : CHttpSessionBase(), |
|
146 iState( EInit ), |
|
147 iGatewayOpen( EFalse ) |
|
148 { |
|
149 CLOG(( EWapConn, 2, _L("CHttpWapSession::CHttpWapSession") )); |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------- |
|
153 // CHttpWapSession::ConstructL() |
|
154 // --------------------------------------------------------- |
|
155 // |
|
156 void CHttpWapSession::ConstructL( const TDesC8& aGateway ) |
|
157 { |
|
158 __ASSERT_ALWAYS( aGateway.Length(), CodPanic( ECodInvalidArguments ) ); |
|
159 iSess.OpenL( KCodWspProtocol ); |
|
160 iSess.StringPool().OpenL( HttpFilterCommonStringsExt::GetTable() ); |
|
161 iGateway = iSess.StringPool().OpenFStringL( aGateway ); |
|
162 // Track whether open - cannot close unopened RStringF. |
|
163 iGatewayOpen = ETrue; |
|
164 iWait = new (ELeave) CActiveSchedulerWait; |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------- |
|
168 // CHttpWapSession::MHFSessionRunL() |
|
169 // --------------------------------------------------------- |
|
170 // |
|
171 void CHttpWapSession::MHFSessionRunL( const THTTPSessionEvent& aEvent ) |
|
172 { |
|
173 CLOG(( EWapConn, 0, _L("-> CHttpWapSession::MHFSessionRunL event(%d)"), \ |
|
174 aEvent.iStatus )); |
|
175 |
|
176 switch ( aEvent.iStatus ) |
|
177 { |
|
178 case THTTPSessionEvent::EConnectedOK: |
|
179 case THTTPSessionEvent::EConnectedWithReducedCapabilities: |
|
180 { |
|
181 CLOG(( EWapConn, 3, _L(" EConnected...") )); |
|
182 if ( iState == EConnecting ) |
|
183 { |
|
184 // Connecting: we are done. |
|
185 iState = EConnected; |
|
186 Done( KErrNone ); |
|
187 } |
|
188 else if ( iState == EDisconnecting ) |
|
189 { |
|
190 // Connecting was interrupted with a Disconnect call but it |
|
191 // seems we have already connected by that time. Now we are |
|
192 // not Done() yet: wait more for the disconnect to finish. |
|
193 CLOG(( EWapConn, 3, \ |
|
194 _L(" late connect event, keep waiting for disconnect") )); |
|
195 iState = EConnected; |
|
196 } |
|
197 else |
|
198 { |
|
199 // Unexpected state for these events. |
|
200 CLOG(( EWapConn, 0, \ |
|
201 _L(" connect event in unexpected state") )); |
|
202 CodPanic( ECodOffState ); |
|
203 } |
|
204 break; |
|
205 } |
|
206 |
|
207 case THTTPSessionEvent::EDisconnected: |
|
208 { |
|
209 CLOG(( EWapConn, 3, _L(" EDisconnected") )); |
|
210 iState = EInit; |
|
211 Done( KErrCodWapConnectionDropped ); |
|
212 break; |
|
213 } |
|
214 |
|
215 case THTTPSessionEvent::EConnectionTimedOut: |
|
216 { |
|
217 CLOG(( EWapConn, 3, _L(" EConnectionTimedOut") )); |
|
218 iState = EInit; |
|
219 Done( KErrCodHttpTimedOut ); |
|
220 break; |
|
221 } |
|
222 |
|
223 default: |
|
224 { |
|
225 if( aEvent.iStatus < 0 ) |
|
226 { |
|
227 // Negative value indicates error. |
|
228 iState = EInit; |
|
229 Done( KErrCodWapConnectionDropped ); |
|
230 } |
|
231 break; |
|
232 } |
|
233 } |
|
234 CLOG(( EWapConn, 0, _L("<- CHttpWapSession::MHFSessionRunL") )); |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------- |
|
238 // CHttpWapSession::MHFSessionRunError() |
|
239 // --------------------------------------------------------- |
|
240 // |
|
241 TInt CHttpWapSession::MHFSessionRunError |
|
242 ( TInt LOG_ONLY( aError ), const THTTPSessionEvent& /*aEvent*/ ) |
|
243 { |
|
244 CLOG(( EWapConn, 2, \ |
|
245 _L("CHttpWapSession::MHFSessionRunError (%d)"), aError )); |
|
246 // This method should never be called - MHFSessionRunL does not leave. |
|
247 CodPanic( ECodInternal ); |
|
248 return KErrNone; |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------- |
|
252 // CHttpWapSession::Done() |
|
253 // --------------------------------------------------------- |
|
254 // |
|
255 void CHttpWapSession::Done( TInt aResult ) |
|
256 { |
|
257 CLOG(( EConn, 2, _L("CHttpWapSession::Done aResult(%d)"), aResult )); |
|
258 if ( iWait->IsStarted() ) |
|
259 { |
|
260 // This must be Disconnect: we are waiting for it. |
|
261 CLOG(( EConn, 3, _L(" stopping wait") )); |
|
262 iWait->AsyncStop(); |
|
263 } |
|
264 if ( iParentStatus ) |
|
265 { |
|
266 // This must be ConnectL: parent is waiting for it. |
|
267 CLOG(( EConn, 3, _L(" completing parent") )); |
|
268 User::RequestComplete( iParentStatus, aResult ); |
|
269 iParentStatus = NULL; |
|
270 } |
|
271 } |