|
1 // Copyright (c) 2002-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 // $Header$ |
|
15 // This module implements the HTTP Framework clas |
|
16 // by: irees, December 2002 |
|
17 // for: Typhoon (7.0s) & JetStream (8.0) |
|
18 // Include Files |
|
19 // |
|
20 // |
|
21 |
|
22 #include <commdbconnpref.h> |
|
23 #include "CHTTPFamily.h" |
|
24 #include "HttpFrmwrk.h" |
|
25 #include "CWspEventDispatcher.h" |
|
26 |
|
27 //----------------------------------------------------------------------------- |
|
28 |
|
29 _LIT(KITHIAP, "IAP"); // Integration Test Harness $$ var name |
|
30 |
|
31 // Proxy information properties |
|
32 _LIT(KITHWspProxyAddress, "ProxyAddress"); |
|
33 _LIT(KITHWspBearer,"Bearer"); |
|
34 _LIT(KITHWspLocalPort, "LocalPort"); |
|
35 _LIT(KITHWspRemotePort, "RemotePort"); |
|
36 _LIT(KITHWspServiceNumber, "ServiceNumber"); |
|
37 _LIT(KITHWspSessionType, "SessionType"); |
|
38 _LIT(KITHWspSecurity, "Security"); |
|
39 |
|
40 _LIT(KITHWspBearerSMS, "SMS"); |
|
41 _LIT(KITHWspSessionTypeCL, "ConnectionLess"); |
|
42 |
|
43 _LIT(KITHWspSecurityUseWTLS, "UseWTLS"); |
|
44 |
|
45 // Capability properties |
|
46 _LIT(KITHWspClientMsgSize, "ClientMsgSize"); |
|
47 _LIT(KITHWspServerMsgSize, "ServerMsgSize"); |
|
48 _LIT(KITHWspUseAcknowledgements, "UseAcknowldegements"); |
|
49 _LIT(KITHWspSupportSuspendResume, "SupportSuspendResume"); |
|
50 _LIT(KITHWspMaxOutstandingRequests, "MaxOutstandingRq"); |
|
51 |
|
52 CFrmwrkSession *CFrmwrkSession::NewL(const TDesC& aName, |
|
53 const TDesC& aFramework, |
|
54 CTEngine *aTestMachine) |
|
55 { |
|
56 CFrmwrkSession *self = NewLC( aName, aFramework, aTestMachine ); |
|
57 CleanupStack::Pop(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 //----------------------------------------------------------------------------- |
|
62 |
|
63 CFrmwrkSession *CFrmwrkSession::NewLC(const TDesC& aName, |
|
64 const TDesC& aFramework, |
|
65 CTEngine *aTestMachine) |
|
66 { |
|
67 CFrmwrkSession *self = new (ELeave) CFrmwrkSession(); |
|
68 CleanupStack::PushL(self); |
|
69 self->ConstructL(aName, aFramework, aTestMachine); |
|
70 return self; |
|
71 } |
|
72 |
|
73 //----------------------------------------------------------------------------- |
|
74 |
|
75 void CFrmwrkSession::ConstructL(const TDesC& aName, |
|
76 const TDesC& aFramework, |
|
77 CTEngine *aTestMachine) |
|
78 { |
|
79 iEngine = aTestMachine ; |
|
80 |
|
81 iName = aName.AllocLC(); |
|
82 CleanupStack::Pop(); |
|
83 |
|
84 iState = ENormal; |
|
85 iuseWSPProtocol = (aFramework.CompareF(THA_KTxtFrameworkWSP) == 0); |
|
86 |
|
87 } |
|
88 |
|
89 //----------------------------------------------------------------------------- |
|
90 |
|
91 CFrmwrkSession::~CFrmwrkSession(void) |
|
92 { |
|
93 delete iName; |
|
94 } |
|
95 |
|
96 void CFrmwrkSession::Log(TRefByValue<const TDesC> aFmt, ... ) |
|
97 { |
|
98 VA_LIST list; |
|
99 VA_START(list, aFmt); |
|
100 |
|
101 Machine()->MsgPrintfln(aFmt, list); |
|
102 } |
|
103 |
|
104 TInt CFrmwrkSession::OpenL() |
|
105 { |
|
106 if (iuseWSPProtocol) |
|
107 { |
|
108 iSession.OpenL(_L8("WSP/WSP")); |
|
109 } |
|
110 else |
|
111 { |
|
112 iSession.OpenL(); |
|
113 } |
|
114 |
|
115 iSession.SetSessionEventCallback(this); |
|
116 |
|
117 return 0 ; |
|
118 } |
|
119 |
|
120 TInt CFrmwrkSession::Close() |
|
121 { |
|
122 iSession.Close(); |
|
123 iConnection.Close() ; |
|
124 |
|
125 return 0 ; |
|
126 } |
|
127 |
|
128 |
|
129 TInt CFrmwrkSession::DisconnectL() |
|
130 { |
|
131 TPtrC myName = Name() ; |
|
132 |
|
133 Log(_L("Disconnecting %S"), &myName); |
|
134 |
|
135 iState = EWSPDisconnecting; |
|
136 iSession.DisconnectL(); |
|
137 |
|
138 return 0 ; |
|
139 } |
|
140 |
|
141 |
|
142 //----------------------------------------------------------------------------- |
|
143 |
|
144 void CFrmwrkSession::SetWspProxyPropertiesL(RHTTPSession & aSession, RStringPool &aStrPool) |
|
145 { |
|
146 RHTTPConnectionInfo connInfo = aSession.ConnectionInfo(); |
|
147 TPtrC valuePtr; |
|
148 |
|
149 valuePtr.Set (Machine()->GetDefine(KITHWspProxyAddress)); |
|
150 if (valuePtr.Length() != 0) |
|
151 { |
|
152 HBufC8* valueBuff8 = HBufC8::NewLC(valuePtr.Length()); |
|
153 TPtr8 valuePtr8 = valueBuff8->Des(); |
|
154 valuePtr8.Copy(valuePtr); |
|
155 RStringF value = aStrPool.OpenFStringL(valuePtr8); |
|
156 CleanupClosePushL(value); |
|
157 |
|
158 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspProxyAddress, RHTTPSession::GetTable()), value); |
|
159 CleanupStack::PopAndDestroy(2); |
|
160 } |
|
161 |
|
162 valuePtr.Set(Machine()->GetDefine(KITHWspBearer)); |
|
163 if (valuePtr.Length() != 0) |
|
164 { |
|
165 RStringF bearer; |
|
166 |
|
167 if (valuePtr.CompareF(KITHWspBearerSMS)==0) |
|
168 bearer = aStrPool.StringF(HTTP::EWspSMS, RHTTPSession::GetTable()); |
|
169 else |
|
170 bearer = aStrPool.StringF(HTTP::EWspIp, RHTTPSession::GetTable()); |
|
171 |
|
172 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspBearer, RHTTPSession::GetTable()), bearer); |
|
173 } |
|
174 |
|
175 valuePtr.Set(Machine()->GetDefine(KITHWspLocalPort)); |
|
176 |
|
177 if (valuePtr.Length() != 0) |
|
178 { |
|
179 TLex lex(valuePtr); |
|
180 TInt localPort = 0; |
|
181 lex.Val(localPort); |
|
182 |
|
183 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspLocalPort, RHTTPSession::GetTable()), localPort); |
|
184 } |
|
185 |
|
186 valuePtr.Set(Machine()->GetDefine(KITHWspRemotePort)); |
|
187 if (valuePtr.Length() != 0) |
|
188 { |
|
189 TLex lex(valuePtr); |
|
190 TInt remotePort = 0; |
|
191 lex.Val(remotePort); |
|
192 |
|
193 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspRemotePort, RHTTPSession::GetTable()), remotePort); |
|
194 } |
|
195 |
|
196 valuePtr.Set(Machine()->GetDefine(KITHWspServiceNumber)); |
|
197 if (valuePtr.Length() != 0) |
|
198 { |
|
199 HBufC8* valueBuff8 = HBufC8::NewLC(valuePtr.Length()); |
|
200 TPtr8 valuePtr8 = valueBuff8->Des(); |
|
201 valuePtr8.Copy(valuePtr); |
|
202 RStringF value = aStrPool.OpenFStringL(valuePtr8); |
|
203 CleanupClosePushL(value); |
|
204 |
|
205 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspServiceNumber, RHTTPSession::GetTable()), value); |
|
206 CleanupStack::PopAndDestroy(2); |
|
207 } |
|
208 |
|
209 valuePtr.Set(Machine()->GetDefine(KITHWspSessionType)); |
|
210 if (valuePtr.Length() != 0) |
|
211 { |
|
212 RStringF sessionType; |
|
213 |
|
214 if (valuePtr.CompareF(KITHWspSessionTypeCL)==0) |
|
215 sessionType = aStrPool.StringF(HTTP::EWspConnectionLess, RHTTPSession::GetTable()); |
|
216 else |
|
217 sessionType = aStrPool.StringF(HTTP::EWspConnectionOriented, RHTTPSession::GetTable()); |
|
218 |
|
219 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspSessionType, RHTTPSession::GetTable()), sessionType); |
|
220 } |
|
221 |
|
222 valuePtr.Set(Machine()->GetDefine(KITHWspSecurity)); |
|
223 if (valuePtr.Length() != 0) |
|
224 { |
|
225 RStringF security; |
|
226 |
|
227 if (valuePtr.CompareF(KITHWspSecurityUseWTLS)==0) |
|
228 security = aStrPool.StringF(HTTP::EWspUseWtls, RHTTPSession::GetTable()); |
|
229 else |
|
230 security = aStrPool.StringF(HTTP::EWspDoNotUseWtls, RHTTPSession::GetTable()); |
|
231 |
|
232 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspSecurity, RHTTPSession::GetTable()), security); |
|
233 } |
|
234 } |
|
235 |
|
236 void CFrmwrkSession::SetWspCapabilityPropertiesL(RHTTPSession & aSession, RStringPool &aStrPool) |
|
237 { |
|
238 RHTTPConnectionInfo connInfo = aSession.ConnectionInfo(); |
|
239 TPtrC valuePtr; |
|
240 |
|
241 valuePtr.Set (Machine()->GetDefine(KITHWspClientMsgSize)); |
|
242 if (valuePtr.Length() != 0) |
|
243 { |
|
244 TLex lex(valuePtr); |
|
245 TInt cliMsgSize = 0; |
|
246 lex.Val(cliMsgSize); |
|
247 |
|
248 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspCapClientMessageSize, RHTTPSession::GetTable()), cliMsgSize); |
|
249 } |
|
250 |
|
251 valuePtr.Set (Machine()->GetDefine(KITHWspServerMsgSize)); |
|
252 if (valuePtr.Length() != 0) |
|
253 { |
|
254 TLex lex(valuePtr); |
|
255 TInt srvMsgSize = 0; |
|
256 lex.Val(srvMsgSize); |
|
257 |
|
258 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspCapServerMessageSize, RHTTPSession::GetTable()), srvMsgSize); |
|
259 } |
|
260 |
|
261 valuePtr.Set(Machine()->GetDefine(KITHWspUseAcknowledgements)); |
|
262 if (valuePtr.Length() != 0) |
|
263 { |
|
264 if (valuePtr.CompareF(KTxtTrue)==0) |
|
265 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspCapUseAcknowledgements, RHTTPSession::GetTable()), THTTPHdrVal(1)); |
|
266 } |
|
267 |
|
268 valuePtr.Set(Machine()->GetDefine(KITHWspSupportSuspendResume)); |
|
269 if (valuePtr.Length() != 0) |
|
270 { |
|
271 if (valuePtr.CompareF(KTxtTrue)==0) |
|
272 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspCapSupportSuspendResume, RHTTPSession::GetTable()), THTTPHdrVal(1)); |
|
273 } |
|
274 |
|
275 valuePtr.Set(Machine()->GetDefine(KITHWspMaxOutstandingRequests)); |
|
276 if (valuePtr.Length() != 0) |
|
277 { |
|
278 TLex lex(valuePtr); |
|
279 TInt maxOutReqs = 0; |
|
280 lex.Val(maxOutReqs); |
|
281 |
|
282 connInfo.SetPropertyL(aStrPool.StringF(HTTP::EWspCapMaxOutstandingRequests, RHTTPSession::GetTable()), maxOutReqs); |
|
283 } |
|
284 |
|
285 } |
|
286 |
|
287 TPtrC CFrmwrkSession::Name() const |
|
288 { |
|
289 TPtrC name(iName->Des()); |
|
290 return name; |
|
291 } |
|
292 |
|
293 TInt CFrmwrkSession::SetPropertiesL() |
|
294 { |
|
295 if (iuseWSPProtocol) |
|
296 { |
|
297 RStringPool strPool = iSession.StringPool(); |
|
298 |
|
299 SetWspProxyPropertiesL(iSession, strPool); |
|
300 |
|
301 SetWspCapabilityPropertiesL(iSession, strPool); |
|
302 } |
|
303 |
|
304 return 0 ; |
|
305 } |
|
306 |
|
307 TInt CFrmwrkSession::ConnectL() |
|
308 { |
|
309 |
|
310 iState = EWSPConnecting; |
|
311 iSession.ConnectL(); |
|
312 |
|
313 TBuf8<16> bufCommDbId; |
|
314 TInt commDbId = 0 ; |
|
315 |
|
316 bufCommDbId.Copy(iEngine->GetDefine(KITHIAP)); |
|
317 |
|
318 if (bufCommDbId.Length()) |
|
319 { |
|
320 TLex8 lexer(bufCommDbId); |
|
321 |
|
322 if ((lexer.Val(commDbId) != KErrNone) || (commDbId < 0) || (commDbId > 8)) |
|
323 { |
|
324 Log(THA_KFmtErrIAPVal, &bufCommDbId); |
|
325 return (KErrArgument) ; |
|
326 } |
|
327 } |
|
328 |
|
329 if (commDbId) |
|
330 { |
|
331 RSocketServ sock; |
|
332 |
|
333 User::LeaveIfError(sock.Connect()); |
|
334 |
|
335 TCommDbConnPref prefs1; |
|
336 |
|
337 prefs1.SetIapId(commDbId); |
|
338 |
|
339 //Start Connection1 |
|
340 |
|
341 User::LeaveIfError(iConnection.Open(sock)); |
|
342 |
|
343 User::LeaveIfError(iConnection.Start(prefs1)); |
|
344 |
|
345 //Set properties for mySession |
|
346 RStringPool strPool = iSession.StringPool(); |
|
347 RHTTPConnectionInfo connInfo1 = iSession.ConnectionInfo(); |
|
348 |
|
349 connInfo1.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ, |
|
350 RHTTPSession::GetTable() ), |
|
351 THTTPHdrVal (sock.Handle()) ); |
|
352 |
|
353 TInt connPtr = REINTERPRET_CAST(TInt, &iConnection); |
|
354 |
|
355 connInfo1.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection, |
|
356 RHTTPSession::GetTable() ), |
|
357 THTTPHdrVal (connPtr) ); |
|
358 } |
|
359 |
|
360 InstallAuthenticationL(iSession); |
|
361 |
|
362 return 0 ; |
|
363 } |
|
364 |
|
365 //----------------------------------------------------------------------------- |
|
366 // Called when a authenticated page is requested |
|
367 // Asks the user for a username and password that would be appropriate for the url that was |
|
368 // supplied. |
|
369 |
|
370 TBool CFrmwrkSession::GetCredentialsL( const TUriC8& aURI, |
|
371 RString aRealm, |
|
372 RStringF aAuthenticationType, |
|
373 RString& aUsername, |
|
374 RString& aPassword) |
|
375 |
|
376 { |
|
377 TBuf<80> scratch; |
|
378 TBuf8<80> scratch8; |
|
379 |
|
380 scratch8.Format(_L8("Enter credentials for URL %S, realm %S"), &aURI.UriDes(), &aRealm.DesC()); |
|
381 scratch.Copy(scratch8); |
|
382 |
|
383 Log(_L("%S"), &scratch); |
|
384 scratch.Copy(aAuthenticationType.DesC()); |
|
385 Log(_L("Using %S authentication"), &scratch); |
|
386 Machine()->GetUserInput(_L("Username (or QUIT to give up): "), scratch); |
|
387 scratch8.Copy(scratch); |
|
388 if (scratch8.CompareF(_L8("quit"))) |
|
389 { |
|
390 TRAPD(err, aUsername = aRealm.Pool().OpenStringL(scratch8)); |
|
391 if (!err) |
|
392 { |
|
393 Machine()->GetUserInput(_L("Password: "), scratch); |
|
394 scratch8.Copy(scratch); |
|
395 TRAP(err, aPassword = aRealm.Pool().OpenStringL(scratch8)); |
|
396 if (!err) |
|
397 return ETrue; |
|
398 } |
|
399 } |
|
400 |
|
401 return EFalse; |
|
402 } |
|
403 |
|
404 void CFrmwrkSession::MHFSessionRunL(const THTTPSessionEvent& aEvent) |
|
405 { |
|
406 TPtrC name = Name() ; |
|
407 |
|
408 switch (aEvent.iStatus) |
|
409 { |
|
410 case THTTPSessionEvent::EConnect: |
|
411 { |
|
412 Log(_L("CFrmwrkSession::MHFSessionRunL, event EConnect, Session %S"), |
|
413 &name); |
|
414 } break; |
|
415 case THTTPSessionEvent::EConnectedOK: |
|
416 { |
|
417 Log(_L("CFrmwrkSession::MHFSessionRunL, The session has been connected, , Session %S"), |
|
418 &name); |
|
419 } break; |
|
420 case THTTPSessionEvent::EDisconnect: |
|
421 { |
|
422 Log(_L("CFrmwrkSession::MHFSessionRunL, EDisconnect - shouldnt get this because it is an outgoing event, Session %S"), |
|
423 &name); |
|
424 } break; |
|
425 case THTTPSessionEvent::EConnectedWithReducedCapabilities: |
|
426 { |
|
427 Log(_L("CFrmwrkSession::MHFSessionRunL, Session connected with reduced capabilities, , Session %S"), |
|
428 &name); |
|
429 } break; |
|
430 case THTTPSessionEvent::EDisconnected: |
|
431 { |
|
432 iState = EWSPDisconnected; |
|
433 Log(_L("CFrmwrkSession::MHFSessionRunL, Session %S has been disconnected"), |
|
434 &name); |
|
435 } |
|
436 break; |
|
437 case THTTPSessionEvent::EAuthenticatedOK: |
|
438 { |
|
439 Log(_L("CFrmwrkSession::MHFSessionRunL, the authentication handshake succeeded, Session %S"), |
|
440 &name); |
|
441 } break; |
|
442 case THTTPSessionEvent::EAuthenticationFailure: |
|
443 { |
|
444 Log(_L("CFrmwrkSession::MHFSessionRunL, the authentication handshake failed, Session %S"), |
|
445 &name); |
|
446 } break; |
|
447 case THTTPSessionEvent::EConnectionTimedOut: |
|
448 { |
|
449 iState = EWSPDisconnected; |
|
450 Log(_L("CFrmwrkSession::MHFSessionRunL, the connection attempt to the proxy timed out, Session %S"), |
|
451 &name); |
|
452 } break; |
|
453 |
|
454 case THTTPSessionEvent::ENotConnected: |
|
455 { |
|
456 iState = EWSPDisconnected; |
|
457 Log(_L("CFrmwrkSession::MHFSessionRunL, ENotConnected, Session %S"), |
|
458 &name); |
|
459 } |
|
460 break; |
|
461 |
|
462 case THTTPSessionEvent::EExceptionInfo: |
|
463 { |
|
464 iState = EWSPDisconnected; |
|
465 Log(_L("CFrmwrkSession::MHFSessionRunL, EExceptionInfo, Session %S"), |
|
466 &name); |
|
467 } |
|
468 break; |
|
469 |
|
470 case THTTPSessionEvent::ERedirected: |
|
471 { |
|
472 iState = EWSPDisconnected; |
|
473 Log(_L("CFrmwrkSession::MHFSessionRunL, ERedirected, Session %S"), |
|
474 &name); |
|
475 } |
|
476 break; |
|
477 |
|
478 case THTTPSessionEvent::EAlreadyConnecting: |
|
479 { |
|
480 iState = EWSPDisconnected; |
|
481 Log(_L("CFrmwrkSession::MHFSessionRunL, EAlreadyConnecting, Session %S"), |
|
482 &name); |
|
483 } |
|
484 break; |
|
485 |
|
486 case THTTPSessionEvent::EAlreadyConnected: |
|
487 { |
|
488 iState = EWSPDisconnected; |
|
489 Log(_L("CFrmwrkSession::MHFSessionRunL, EAlreadyConnected, Session %S"), |
|
490 &name); |
|
491 } |
|
492 break; |
|
493 |
|
494 case THTTPSessionEvent::EAlreadyDisconnecting: |
|
495 { |
|
496 iState = EWSPDisconnected; |
|
497 Log(_L("CFrmwrkSession::MHFSessionRunL, EAlreadyDisconnecting, Session %S"), |
|
498 &name); |
|
499 } |
|
500 break; |
|
501 |
|
502 case THTTPSessionEvent::EAlreadyDisconnected: |
|
503 { |
|
504 iState = EWSPDisconnected; |
|
505 Log(_L("CFrmwrkSession::MHFSessionRunL, EAlreadyDisconnected, Session %S"), |
|
506 &name); |
|
507 } |
|
508 break; |
|
509 |
|
510 default: |
|
511 { |
|
512 iState = EWSPDisconnected; |
|
513 Log(_L("CFrmwrkSession::MHFSessionRunL, Unrecognised session event [%d], Session %S[%d]"), |
|
514 aEvent.iStatus, &name); |
|
515 } |
|
516 break; |
|
517 } |
|
518 |
|
519 TRequestStatus* pStat = &iEventDispatcher->iStatus; |
|
520 |
|
521 User::RequestComplete(pStat,aEvent.iStatus); |
|
522 } |
|
523 |
|
524 TInt CFrmwrkSession::MHFSessionRunError(TInt aError, const THTTPSessionEvent& /*aEvent*/) |
|
525 { |
|
526 iEngine->LogPrintf(_L("CFrmwrkSession::MHFSessionRunError, error code %d"), aError); |
|
527 |
|
528 TRequestStatus* pStat = &iEventDispatcher->iStatus; |
|
529 User::RequestComplete(pStat, KErrNone); |
|
530 |
|
531 return KErrNone; |
|
532 } |