|
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 collection of HTTP Framework related integration |
|
16 // test commands and tools |
|
17 // by: mjdavey, symbian@mjdss.com, August 2002 |
|
18 // for: Typhoon (7.0s) & JetStream (8.0) |
|
19 // Include Files |
|
20 // |
|
21 // |
|
22 |
|
23 |
|
24 #include "CHTTPFamily.h" |
|
25 #include "HttpSessionCmds.h" |
|
26 #include "HttpFrmwrk.h" |
|
27 #include "CWspEventDispatcher.h" |
|
28 |
|
29 //----------------------------------------------------------------------------- |
|
30 //----------------------------------------------------------------------------- |
|
31 // Command: CONNECT command. |
|
32 //----------------------------------------------------------------------------- |
|
33 //----------------------------------------------------------------------------- |
|
34 // |
|
35 // Form: |
|
36 // CONNECT <framework> <connection name> |
|
37 // Example: |
|
38 // CONNECT HTTP framework1 |
|
39 // |
|
40 // The connection made is assigned the name <connection name> e.g. 'framework1' |
|
41 // and is referenced by subsequent tagname replacement. |
|
42 // the connection session is then associated with this tagname and can be |
|
43 // used until the corresponding DISCONNECT <connection name> is encountered. |
|
44 // The 'Engine' has an arbitrary collection object that is used to maintain these |
|
45 // links |
|
46 |
|
47 CCmdConnect *CCmdConnect::NewL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
48 { |
|
49 CCmdConnect *self = NewLC( aCommandId, aKeyphrase, aHelpPhrase); |
|
50 CleanupStack::Pop(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 //----------------------------------------------------------------------------- |
|
55 |
|
56 CCmdConnect *CCmdConnect::NewLC( TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
57 { |
|
58 CCmdConnect *self = new (ELeave) CCmdConnect(); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
61 return self; |
|
62 } |
|
63 |
|
64 //----------------------------------------------------------------------------- |
|
65 |
|
66 void CCmdConnect::ConstructL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
67 { |
|
68 CCmdBase::ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
69 |
|
70 // create the Active Object interface |
|
71 iEventDispatcher = CWspEventDispatcher::NewL(*this); |
|
72 |
|
73 WaitForNextEvent (THTTPSessionEvent::EDisconnected); |
|
74 |
|
75 } |
|
76 |
|
77 //----------------------------------------------------------------------------- |
|
78 |
|
79 CCmdConnect::~CCmdConnect(void) |
|
80 { |
|
81 iEventDispatcher->CancelWait(); |
|
82 |
|
83 delete iEventDispatcher; |
|
84 // void WaitForNextEvent(TInt); |
|
85 } |
|
86 |
|
87 //----------------------------------------------------------------------------- |
|
88 |
|
89 //----------------------------------------------------------------------------- |
|
90 |
|
91 void CCmdConnect::DisconnectL(const TDesC& aLabel) |
|
92 { |
|
93 CAnyObject *obj = (CAnyObject *)Machine()->Domains()->Name(aLabel); |
|
94 CFrmwrkSession *frmwk = (CFrmwrkSession *) obj->Ptr(); |
|
95 TPtrC myName = frmwk->Name() ; |
|
96 |
|
97 |
|
98 Log(_L("CCmdConnect::DisconnectL, Session %S"), &myName); |
|
99 frmwk->DisconnectL(); |
|
100 } |
|
101 |
|
102 void CCmdConnect::DisconnectL(const TInt &aIndex) |
|
103 { |
|
104 CAnyObject *obj = (CAnyObject *)Machine()->Domains()->At(aIndex); |
|
105 CFrmwrkSession *frmwk = (CFrmwrkSession *) obj->Ptr(); |
|
106 TPtrC myName = frmwk->Name() ; |
|
107 |
|
108 |
|
109 Log(_L("CCmdConnect::DisconnectL, Session %S"), &myName); |
|
110 frmwk->DisconnectL(); |
|
111 } |
|
112 |
|
113 void CCmdConnect::Delete(const TDesC& aLabel) |
|
114 { |
|
115 CAnyObject *obj = (CAnyObject *)Machine()->Domains()->Name(aLabel); |
|
116 CFrmwrkSession *frmwk = (CFrmwrkSession *) obj->Ptr(); |
|
117 TPtrC myName = frmwk->Name() ; |
|
118 |
|
119 Log(_L("CCmdConnect::Delete, Session %S"), &myName); |
|
120 frmwk->Close(); |
|
121 delete frmwk; |
|
122 } |
|
123 |
|
124 TInt CCmdConnect::ProcessL( const TDesC& aCommand ) |
|
125 { |
|
126 // Complete the test machine - will then get the next cmd |
|
127 Machine()->CompleteRequest(); |
|
128 |
|
129 TPtrC framework; |
|
130 TPtrC conname; |
|
131 |
|
132 TInt error; |
|
133 if (( error = ParseCmdArgs( aCommand, framework, conname )) != KErrNone) |
|
134 return error; |
|
135 |
|
136 if (conname.Size() != 0) |
|
137 { |
|
138 // Check if the connection already is defined. |
|
139 // If it is return error, if not create a session and ptr! |
|
140 CAnyObject *cnx = (CAnyObject *)Machine()->Domains()->Name(conname); |
|
141 |
|
142 if (cnx != NULL) // already exists |
|
143 return Error(KErrAlreadyExists, THA_KErrCnxionExists, &conname); |
|
144 else |
|
145 { |
|
146 CFrmwrkSession *cithc = CFrmwrkSession::NewLC(conname, framework, Machine()); |
|
147 cithc->iEventDispatcher = iEventDispatcher ; |
|
148 |
|
149 TRAPD(error, cithc->OpenL()); |
|
150 if (error == KErrNone) |
|
151 { |
|
152 cithc->SetPropertiesL(); |
|
153 |
|
154 TRAP(error, cithc->ConnectL()); |
|
155 |
|
156 if (error == KErrNone) |
|
157 { |
|
158 // now create reference to name in domains |
|
159 // note: the value is 1 for HTTP and 0 for WSP |
|
160 Machine()->Domains()->AddL(conname, 0, THA_KHTTP_Connect, (TAny *) cithc); |
|
161 WriteDateStamp(); |
|
162 Log(_L("Connection '%S' has been opened!"), &conname); |
|
163 } |
|
164 else |
|
165 Error(error, KTxtErrConnectFailed); |
|
166 } |
|
167 |
|
168 CleanupStack::Pop(); // cithc |
|
169 } |
|
170 } |
|
171 else |
|
172 { |
|
173 (void) ShowSessions () ; |
|
174 } |
|
175 |
|
176 return error; |
|
177 } |
|
178 |
|
179 TInt CCmdConnect::ParseCmdArgs( const TDesC& aCommand, TPtrC& aFramework, TPtrC& aConName ) |
|
180 { |
|
181 aFramework.Set(NULL, 0); |
|
182 aConName.Set(NULL, 0); |
|
183 TInt error = KErrNone; |
|
184 |
|
185 // get the command into a local string |
|
186 TPtrC param; |
|
187 TRAP(error, param.Set(ParamsL(aCommand))); |
|
188 if (error != KErrNone) |
|
189 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
190 |
|
191 // check its' valid |
|
192 TLex parse(param); |
|
193 if (!parse.Eos() && !parse.Peek().IsSpace()) |
|
194 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
195 |
|
196 // remove any spaces and see if its got params |
|
197 parse.SkipSpace(); |
|
198 if ( parse.Eos() ) // no params |
|
199 return error; |
|
200 |
|
201 // Get framework name, must not exceed 16 characters. |
|
202 // should be http or wsp (currently) |
|
203 |
|
204 TRAP(error, aFramework.Set(TfrLex::GetL(parse))); |
|
205 if ( error != KErrNone) |
|
206 return Error(KErrArgument, TFR_KFmtErrBadCmd, &aFramework); |
|
207 |
|
208 // check is valid length |
|
209 aFramework.Set(TfrLex::Peel(aFramework)); |
|
210 if ( aFramework.Length() > 16 ) |
|
211 return Error(KErrArgument, THA_KErrParameterLong, &aFramework); |
|
212 |
|
213 // check aFramework type valid (HTTP or WSP) |
|
214 // Param shall be HTTP (True) or WSP (False) |
|
215 aFramework.Set( TfrLex::TrimAndPeel(aFramework) ); |
|
216 TBool value = (aFramework.CompareF(THA_KTxtFrameworkHTTP) == 0); |
|
217 |
|
218 if ( !value && (aFramework.CompareF(THA_KTxtFrameworkWSP) != 0)) |
|
219 return Error(KErrArgument, THA_KErrFrameworkErr, &aFramework); |
|
220 |
|
221 // Get connection/session name value. |
|
222 |
|
223 TRAP(error,aConName.Set(TfrLex::GetL(parse))); |
|
224 if ( error != KErrNone) |
|
225 return Error(KErrArgument, TFR_KFmtErrBadCmd, &aConName); |
|
226 |
|
227 // There shall not be anything more. |
|
228 TPtrC remainder = TfrLex::Trim(parse.Remainder()); |
|
229 if ( remainder.Length() > 0 ) |
|
230 return Error(KErrArgument, TFR_KFmtErrBadCmd, &remainder); |
|
231 |
|
232 if (aConName.Length() <= 0) |
|
233 return Error(KErrArgument, THA_KErrInvalidConnect, &Keyphrase()); |
|
234 |
|
235 aConName.Set(TfrLex::Peel(aConName)); |
|
236 return (KErrNone); |
|
237 } |
|
238 |
|
239 void CCmdConnect::ShowSessions () |
|
240 { |
|
241 |
|
242 CObjCatalogue *cnxns = Machine()->Domains(); |
|
243 TInt iCnxns = 0; |
|
244 if (cnxns->Count() == 0) |
|
245 Log(_L("\tNo connections have been defined")); |
|
246 else |
|
247 { |
|
248 Log(_L("\t Name Framework")); |
|
249 for (TInt i = 0; i < cnxns->Count(); ++i) |
|
250 { |
|
251 CAnyObject *obj = (CAnyObject *)cnxns->At(i); |
|
252 if (obj->Tag() == THA_KHTTP_Connect) |
|
253 { |
|
254 TPtrC label = obj->Name(); |
|
255 TPtrC frmwrk = ((TBool) ((CFrmwrkSession *) obj->Ptr())->UseWSPProtocol()) ? _L("WSP") : _L("HTTP"); |
|
256 ++iCnxns; |
|
257 Log(_L("\t%d %S - %S"), iCnxns, &label, &frmwrk); |
|
258 } |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 //----------------------------------------------------------------------------- |
|
264 //----------------------------------------------------------------------------- |
|
265 // Command: DISCONNECT command. |
|
266 //----------------------------------------------------------------------------- |
|
267 //----------------------------------------------------------------------------- |
|
268 // |
|
269 // Form: |
|
270 // DISCONNECT <connection name> |
|
271 // Example: |
|
272 // DISCONNECT framework1 |
|
273 // |
|
274 |
|
275 CCmdDisconnect *CCmdDisconnect::NewL(TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
276 { |
|
277 CCmdDisconnect *self = NewLC( aCommandId, aKeyphrase, aHelpPhrase); |
|
278 CleanupStack::Pop(); |
|
279 return self; |
|
280 } |
|
281 |
|
282 //----------------------------------------------------------------------------- |
|
283 |
|
284 CCmdDisconnect *CCmdDisconnect::NewLC( TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
285 { |
|
286 CCmdDisconnect *self = new (ELeave) CCmdDisconnect(); |
|
287 CleanupStack::PushL(self); |
|
288 self->ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
289 return self; |
|
290 } |
|
291 |
|
292 //----------------------------------------------------------------------------- |
|
293 |
|
294 void CCmdDisconnect::ConstructL( TInt aCommandId, const TDesC& aKeyphrase, const TDesC& aHelpPhrase) |
|
295 { |
|
296 CCmdBase::ConstructL(aCommandId, aKeyphrase, aHelpPhrase); |
|
297 } |
|
298 |
|
299 //----------------------------------------------------------------------------- |
|
300 |
|
301 CCmdDisconnect::~CCmdDisconnect(void) |
|
302 { |
|
303 } |
|
304 |
|
305 TInt CCmdDisconnect::ParseCmdArgs( const TDesC& aCommand, TPtrC& aConName ) |
|
306 { |
|
307 aConName.Set(NULL, 0); |
|
308 |
|
309 // get the command into a local string |
|
310 TPtrC param; |
|
311 TRAPD(error, param.Set(ParamsL(aCommand))); |
|
312 if (error != KErrNone) |
|
313 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
314 |
|
315 // check its' valid |
|
316 TLex parse(param); |
|
317 if (!parse.Eos() && !parse.Peek().IsSpace()) |
|
318 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
319 |
|
320 // remove any spaces and see if its got params |
|
321 parse.SkipSpace(); |
|
322 if (parse.Eos() ) |
|
323 // If no params return error |
|
324 return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
325 |
|
326 // Get connection/session name value. |
|
327 TRAP(error,aConName.Set(TfrLex::GetL(parse))); |
|
328 if (error != KErrNone) |
|
329 return Error(KErrArgument, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
330 |
|
331 // There shall not be anything more. |
|
332 TPtrC remainder = TfrLex::Trim(parse.Remainder()); |
|
333 if (remainder.Length() > 0) |
|
334 return Error(KErrArgument, TFR_KFmtErrBadCmd, &Keyphrase()); |
|
335 |
|
336 if (aConName.Length() <= 0) |
|
337 return Error(KErrArgument, THA_KErrInvalidConnect, &aConName); |
|
338 |
|
339 aConName.Set(TfrLex::Peel(aConName)); |
|
340 return (KErrNone); |
|
341 } |
|
342 |
|
343 TInt CCmdDisconnect::ProcessL(const TDesC& aCommand) |
|
344 { |
|
345 // Complete the test machine - will then get the next cmd |
|
346 Machine()->CompleteRequest(); |
|
347 |
|
348 TInt error; |
|
349 TPtrC conname; |
|
350 if (( error = ParseCmdArgs( aCommand, conname )) != KErrNone) |
|
351 return error; |
|
352 |
|
353 // Check if the connection already is defined. |
|
354 // If it is return error, if not create a session and ptr! |
|
355 CAnyObject *obj = (CAnyObject *) Machine()->Domains()->Name(conname); |
|
356 |
|
357 // at this point we can find the session that the disconnect refers to |
|
358 // in the Session, save disconnects eventhandler. |
|
359 |
|
360 if (obj != NULL) // connection (name) exists |
|
361 { |
|
362 // get reference to list in CmdConnect from Family and retrieve the reference to the session |
|
363 CCmdConnect *iConnect = (CCmdConnect *)Family()->Command(THA_KHTTP_Connect); |
|
364 |
|
365 iConnect->DisconnectL(conname); |
|
366 |
|
367 TBool frmwrk = ((CFrmwrkSession *) obj->Ptr())->UseWSPProtocol() ; |
|
368 |
|
369 if (!frmwrk) // HTTP Session so complete request |
|
370 { |
|
371 // check that there are no existing transactions (live) for this session |
|
372 // and that the session is not already closed (i.e. in error) |
|
373 |
|
374 //XXXXXXX |
|
375 |
|
376 iConnect->Delete(conname); |
|
377 Machine()->Domains()->Delete(conname); |
|
378 |
|
379 // what about the iSessionIndex - this is going to be problematic since we need to track the |
|
380 // index into the session when it changes... |
|
381 WriteDateStamp(); |
|
382 Log(_L("\tConnection '%S' has been disconnected!"), &conname); |
|
383 } |
|
384 else |
|
385 { |
|
386 Log(_L("Issued DisconnectL")); |
|
387 } |
|
388 } |
|
389 else |
|
390 return Error(KErrNotFound, THA_KErrConnectionErr, &conname); |
|
391 |
|
392 if ( error != KErrNone ) |
|
393 Log(TFR_KFmtErrFailed, &Keyphrase(), error); |
|
394 |
|
395 return error; |
|
396 } |
|
397 |
|
398 void CCmdConnect::WaitForNextEvent(TInt aEventType) |
|
399 { |
|
400 // Wait for the next event |
|
401 iEventRequired = aEventType; |
|
402 |
|
403 iEventDispatcher->WaitForWspEvent(); |
|
404 } |
|
405 |
|
406 |
|
407 void CCmdConnect::HandleWspEvent(TRequestStatus aStatus) |
|
408 { |
|
409 TBool fail = EFalse; |
|
410 |
|
411 if (aStatus == THTTPSessionEvent::EConnect) |
|
412 { |
|
413 Log(_L("CFrmwrkSession::HandleWspEvent, event EConnect")); |
|
414 } |
|
415 else if (aStatus == THTTPSessionEvent::EConnectedOK) |
|
416 { |
|
417 Log(_L("CFrmwrkSession::HandleWspEvent, event EConnectedOK")); |
|
418 } |
|
419 else if (aStatus == THTTPSessionEvent::EConnectedWithReducedCapabilities) |
|
420 { |
|
421 Log(_L("CFrmwrkSession::HandleWspEvent, event EConnectedWithReducedCapabilities")); |
|
422 } |
|
423 else if (aStatus == THTTPSessionEvent::EDisconnected) |
|
424 { |
|
425 Log(_L("CFrmwrkSession::HandleWspEvent, event EDisconnected")); |
|
426 fail = ETrue; |
|
427 } |
|
428 else if (aStatus == THTTPSessionEvent::EAuthenticatedOK) |
|
429 { |
|
430 Log(_L("CFrmwrkSession::HandleWspEvent, event EAuthenticatedOK")); |
|
431 } |
|
432 else if (aStatus == THTTPSessionEvent::EAuthenticationFailure) |
|
433 { |
|
434 Log(_L("CFrmwrkSession::HandleWspEvent, event EAuthenticationFailure")); |
|
435 } |
|
436 else if (aStatus == THTTPSessionEvent::EConnectionTimedOut) |
|
437 { |
|
438 Log(_L("CFrmwrkSession::HandleWspEvent, event EConnectionTimedOut")); |
|
439 fail = ETrue; |
|
440 } |
|
441 else |
|
442 { |
|
443 Log(_L("CFrmwrkSession::HandleWspEvent, Unrecognised event [%d]"), aStatus.Int()); |
|
444 fail = ETrue; |
|
445 } |
|
446 |
|
447 if (fail) |
|
448 { |
|
449 CObjCatalogue *sessions = Machine()->Domains(); |
|
450 |
|
451 for (TInt i = 0; i < sessions->Count(); ++i) |
|
452 { |
|
453 CAnyObject *obj = (CAnyObject *)sessions->At(i); |
|
454 if (obj->Tag() == THA_KHTTP_Connect) |
|
455 { |
|
456 CFrmwrkSession *frmwk = (CFrmwrkSession *) obj->Ptr(); |
|
457 |
|
458 if (frmwk->UseWSPProtocol() && (frmwk->iState == CFrmwrkSession::EWSPDisconnected)) |
|
459 { |
|
460 TBuf16<256> myNameBuf; |
|
461 |
|
462 myNameBuf.Copy(frmwk->Name()); |
|
463 |
|
464 Log(_L("CCmdConnect::HandleWspEvent() : Delete %S\r\n"), &myNameBuf); |
|
465 Delete(myNameBuf); |
|
466 Machine()->Domains()->Delete(myNameBuf); |
|
467 |
|
468 } |
|
469 } |
|
470 } |
|
471 } |
|
472 |
|
473 WaitForNextEvent (THTTPSessionEvent::EDisconnected); |
|
474 } |
|
475 |
|
476 //----------------------------------------------------------------------------- |
|
477 // End of File |
|
478 //----------------------------------------------------------------------------- |
|
479 |