|
1 // Copyright (c) 2005-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 #include <es_sock.h> |
|
17 #include <ir_sock.h> |
|
18 #include <bautils.h> |
|
19 #include <usbman.h> |
|
20 #include <d32usbc.h> |
|
21 #include <e32keys.h> |
|
22 #include "clienthandler.h" |
|
23 #include "TOBEXCON.H" |
|
24 #include "btextnotifiers.h" |
|
25 #include "obexconstantsinternal.h" |
|
26 |
|
27 #define EPOCIDENT _L8("EPOC32 ER5") |
|
28 |
|
29 |
|
30 |
|
31 CObexClientHandler::CObexClientHandler(CActiveConsole* aParent) |
|
32 : CActive(EPriorityNormal), iParent(aParent), iState(EIdle) |
|
33 { |
|
34 } |
|
35 |
|
36 CObexClientHandler* CObexClientHandler::NewL(CActiveConsole* aParent, TTransport aTransport) |
|
37 { |
|
38 CObexClientHandler* self = new (ELeave) CObexClientHandler(aParent); |
|
39 |
|
40 CleanupStack::PushL (self); |
|
41 self->ConstructL(aTransport); |
|
42 CActiveScheduler::Add (self); |
|
43 CleanupStack::Pop (); |
|
44 return (self); |
|
45 } |
|
46 |
|
47 void CObexClientHandler::ConstructL(TTransport aTransport) |
|
48 { |
|
49 if (aTransport == EBluetooth) |
|
50 { |
|
51 // Check if an address has been provided on the cmd line. |
|
52 TBuf<20> cmdline; |
|
53 User::CommandLine(cmdline); |
|
54 |
|
55 TInt ret = iDevAddr.SetReadable(cmdline); |
|
56 if (ret < KErrNone) |
|
57 { |
|
58 iParent->Console()->Printf(_L("\nNo address found on command line\n")); |
|
59 |
|
60 //Ask user which device address we should connect to... |
|
61 RNotifier notify; |
|
62 User::LeaveIfError(notify.Connect()); |
|
63 TBTDeviceSelectionParamsPckg pckg; |
|
64 TBTDeviceResponseParamsPckg resPckg; |
|
65 TRequestStatus stat; |
|
66 notify.StartNotifierAndGetResponse(stat, KDeviceSelectionNotifierUid, pckg, resPckg); |
|
67 User::WaitForRequest(stat); |
|
68 notify.CancelNotifier(KDeviceSelectionNotifierUid); |
|
69 notify.Close(); |
|
70 User::LeaveIfError(stat.Int()); |
|
71 |
|
72 iDevAddr = resPckg().BDAddr(); |
|
73 } |
|
74 |
|
75 // Find UUID to search for |
|
76 iParent->Console()->Printf(_L("\nPress F: FTP, Any other key: OPP")); |
|
77 TChar code (iParent->Console()->Getch()); |
|
78 TUUID searchUUID; |
|
79 switch(code) |
|
80 { |
|
81 case 'f': case 'F': |
|
82 searchUUID = TUUID(0x1106); //FTP |
|
83 break; |
|
84 case 'o': case 'O': |
|
85 default: |
|
86 searchUUID = TUUID(0x1105); //OPP |
|
87 } |
|
88 |
|
89 //start the SDP Query |
|
90 delete iSdpServiceFinder; |
|
91 iSdpServiceFinder=0; |
|
92 iSdpServiceFinder = CRFCOMMServiceFinder::NewL(searchUUID, iDevAddr, *this); |
|
93 iSdpServiceFinder->FindPortL(); |
|
94 iParent->Console()->Printf(_L("\nSearching for SDP service....\n")); |
|
95 |
|
96 // For bluetooth the client is created in SearchResult(). |
|
97 } |
|
98 else if (aTransport == EIrda) |
|
99 { |
|
100 TObexIrProtocolInfo aInfo; |
|
101 aInfo.iTransport= KObexIrTTPProtocolV2; |
|
102 aInfo.iClassName = _L8("OBEX"); //same for unicode and narrow builds |
|
103 aInfo.iAttributeName = _L8("IrDA:TinyTP:LsapSel"); |
|
104 aInfo.iDiscoverySlots = iParent->iDiscoverySlots; |
|
105 aInfo.iDiscoveryAttempts = iParent->iDiscoveryAttempts; |
|
106 //now create the obex client... |
|
107 iClient = CObexClient::NewL (aInfo); |
|
108 iClient->SetFinalPacketObserver(this); |
|
109 #ifdef ERROR_RESOLUTION_EXTENSION |
|
110 iClientErrorResolver = CObexClientErrorResolver::NewL(*iClient); |
|
111 #endif // ERROR_RESOLUTION_EXTENSION |
|
112 } |
|
113 else if (aTransport == EUsb) |
|
114 { |
|
115 TObexUsbProtocolInfo aInfo; |
|
116 aInfo.iTransport = KObexUsbProtocol; |
|
117 aInfo.iInterfaceStringDescriptor = _L("TOBEX Client Interface"); |
|
118 //now create the obex client... |
|
119 iClient = CObexClient::NewL (aInfo); |
|
120 iClient->SetFinalPacketObserver(this); |
|
121 #ifdef ERROR_RESOLUTION_EXTENSION |
|
122 iClientErrorResolver = CObexClientErrorResolver::NewL(*iClient); |
|
123 #endif // ERROR_RESOLUTION_EXTENSION |
|
124 } |
|
125 else if (aTransport == EWin32Usb) |
|
126 { |
|
127 TObexUsbProtocolInfo aInfo; |
|
128 aInfo.iTransport = _L("Win32Usb"); |
|
129 //now create the obex client... |
|
130 iClient = CObexClient::NewL (aInfo); |
|
131 iClient->SetFinalPacketObserver(this); |
|
132 #ifdef ERROR_RESOLUTION_EXTENSION |
|
133 iClientErrorResolver = CObexClientErrorResolver::NewL(*iClient); |
|
134 #endif // ERROR_RESOLUTION_EXTENSION |
|
135 } |
|
136 else |
|
137 { |
|
138 User::Invariant(); |
|
139 } |
|
140 |
|
141 #ifdef EMPTY_HEADERS_TEST |
|
142 iObexEmptyHeaderTest = CObexEmptyHeaderTest::NewL(); |
|
143 #endif //EMPTY_HEADERS_TEST |
|
144 iFileObject = CObexFileObject::NewL(); |
|
145 iObjectBuffer = CBufFlat::NewL(8); |
|
146 iObject = CObexBufObject::NewL(iObjectBuffer); |
|
147 iObexName = _L(""); |
|
148 iGetType = _L("text/x-vcard"); |
|
149 |
|
150 iFilename1 = _L("Contacts.vcf"); |
|
151 iFilename2 = _L("Contacts2.vcf"); |
|
152 iFilename3 = _L("Contacts3.vcf"); |
|
153 |
|
154 iChallengePassword = _L("SecretPassword"); |
|
155 iResponsePassword = _L("SecretPassword"); |
|
156 |
|
157 iTargetHeaderObject = CObexNullObject::NewL(); |
|
158 iTargetHeaderObject->SetTargetL(KRefTarget); |
|
159 iTargetHeaderObject->SetHeaderMask(KObexHdrTarget); |
|
160 } |
|
161 |
|
162 |
|
163 void CObexClientHandler::SearchResult(TInt aError, TUint8 aPort, TInt aProfileVersion) |
|
164 { |
|
165 if (aError != KErrNone) |
|
166 { |
|
167 iParent->Console()->Printf(_L("\r\n Could not find SDP service in remote device : error %d \r\n"),aError); |
|
168 iParent->ClientErrored(); |
|
169 return; |
|
170 } |
|
171 |
|
172 if (aProfileVersion >= 0) |
|
173 { |
|
174 iParent->Console()->Printf(_L("\nProfile Version 0x%04x\n"), aProfileVersion); |
|
175 } |
|
176 else |
|
177 { |
|
178 iParent->Console()->Printf(_L("\nProfile Version not supplied\n")); |
|
179 } |
|
180 iParent->Console()->Printf(_L("RFCOMM Port %d\n"), aPort); |
|
181 |
|
182 TObexBluetoothProtocolInfo aInfo; |
|
183 aInfo.iAddr.SetBTAddr(iDevAddr); |
|
184 aInfo.iAddr.SetPort(aPort); |
|
185 aInfo.iTransport = KObexRfcommProtocol; |
|
186 |
|
187 TObexProtocolPolicy policy; |
|
188 policy.SetReceiveMtu(iParent->iRecvMTU); |
|
189 policy.SetTransmitMtu(iParent->iTransmitMTU); |
|
190 |
|
191 //now create the obex client... |
|
192 TRAP(aError, iClient = CObexClient::NewL(aInfo, policy)); |
|
193 if (aError) |
|
194 { |
|
195 iParent->Console()->Printf(_L("\r\n Could not create client! : error %d \r\n"),aError); |
|
196 iParent->ClientErrored(); |
|
197 return; |
|
198 } |
|
199 iClient->SetFinalPacketObserver(this); |
|
200 #ifdef ERROR_RESOLUTION_EXTENSION |
|
201 TRAP(aError,iClientErrorResolver = CObexClientErrorResolver::NewL(*iClient)); |
|
202 if (aError != KErrNone) |
|
203 { |
|
204 iParent->Console()->Printf(_L("\r\n Could not create client error resolver! : error %d \r\n"),aError); |
|
205 iParent->ClientErrored(); |
|
206 return; |
|
207 } |
|
208 #endif // ERROR_RESOLUTION_EXTENSION |
|
209 iParent->Console()->Printf(_L("\nSDP search complete OK!\n")); |
|
210 iParent->iTestMode = E_Client; |
|
211 |
|
212 iParent->Cancel(); // cancel request for key |
|
213 iParent->RequestCharacter(); // re-request, to re-display menu |
|
214 } |
|
215 |
|
216 void CObexClientHandler::SetCurrentTestNumber() |
|
217 { |
|
218 iCurrentTestNumber = 1; |
|
219 } |
|
220 |
|
221 void CObexClientHandler::ResetCurrentTestNumber() |
|
222 { |
|
223 iCurrentTestNumber = 0; |
|
224 } |
|
225 |
|
226 void CObexClientHandler::MofpoFinalPacketStarted() |
|
227 { |
|
228 iParent->Console()->Printf(_L("\nFinal packet started\n")); |
|
229 } |
|
230 |
|
231 void CObexClientHandler::MofpoFinalPacketFinished() |
|
232 { |
|
233 iParent->Console()->Printf(_L("\nFinal packet finished\n")); |
|
234 } |
|
235 |
|
236 CObexClientHandler::~CObexClientHandler() |
|
237 { |
|
238 Cancel(); |
|
239 #ifdef EMPTY_HEADERS_TEST |
|
240 delete iObexEmptyHeaderTest; |
|
241 #endif //EMPTY_HEADERS_TEST |
|
242 delete iObject; |
|
243 delete iFileObject; |
|
244 delete iClient; |
|
245 #ifdef ERROR_RESOLUTION_EXTENSION |
|
246 delete iClientErrorResolver; |
|
247 #endif // ERROR_RESOLUTION_EXTENSION |
|
248 |
|
249 delete iObjectBuffer; |
|
250 delete iTargetHeaderObject; |
|
251 delete iSdpServiceFinder; |
|
252 } |
|
253 |
|
254 void CObexClientHandler::Abort() |
|
255 { |
|
256 if((iState != EPutting)&&(iState != EGetting)) |
|
257 iParent->Console()->Printf(_L("\r\n NOTE: Wrong Obex state for issuing abort\r\n")); |
|
258 iClient->Abort(); |
|
259 } |
|
260 |
|
261 |
|
262 |
|
263 void CObexClientHandler::Connect() |
|
264 { |
|
265 if(IsActive()) |
|
266 { |
|
267 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
268 return; |
|
269 } |
|
270 |
|
271 TObexConnectInfo iLocalInfo = iClient->LocalInfo(); |
|
272 iLocalInfo.iWho = _L8(""); |
|
273 iLocalInfo.iWho = EPOCIDENT; |
|
274 iLocalInfo.iWho.Append(_L8(" EikIrOBEXFile ")); |
|
275 |
|
276 iClient->Connect(iStatus); |
|
277 SetActive(); |
|
278 iState = EConnecting; |
|
279 } |
|
280 |
|
281 void CObexClientHandler::RemoteAddress() |
|
282 { |
|
283 TSockAddr aAddr; |
|
284 iClient->RemoteAddr( aAddr); |
|
285 TBTDevAddr addr = static_cast <TBTSockAddr>(aAddr).BTAddr(); |
|
286 |
|
287 TChar aChar; |
|
288 |
|
289 iParent->Console()->Printf(_L("Remote Address = ")); |
|
290 for(TInt count = 0; count < addr.Des().Length(); count++) |
|
291 { |
|
292 aChar = (addr.Des()[count] & 0xf0)>>4; |
|
293 if (aChar <= 9) |
|
294 aChar += 0x30; |
|
295 else if ((aChar >= 0x0a) && (aChar <= 0x0f)) |
|
296 aChar += 'A' - 0x0a; |
|
297 iParent->Console()->Printf(_L("%C"),(TUint)aChar); |
|
298 |
|
299 aChar = (addr.Des()[count] & 0x0f); |
|
300 if (aChar <= 9) |
|
301 aChar += 0x30; |
|
302 else if ((aChar >= 0x0a) && (aChar <= 0x0f)) |
|
303 aChar += 'A' - 0x0a; |
|
304 iParent->Console()->Printf(_L("%C"),(TUint)aChar); |
|
305 } |
|
306 iParent->Console()->Printf(_L("\r\n")); |
|
307 |
|
308 } |
|
309 |
|
310 void CObexClientHandler::Disconnect() |
|
311 { |
|
312 if(IsActive()) |
|
313 { |
|
314 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
315 return; |
|
316 } |
|
317 |
|
318 iClient->Disconnect(iStatus); |
|
319 SetActive(); |
|
320 iState = EDisconnecting; |
|
321 } |
|
322 |
|
323 void CObexClientHandler::GetByNameL() |
|
324 { |
|
325 if(IsActive()) |
|
326 { |
|
327 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
328 return; |
|
329 } |
|
330 |
|
331 iObject->Reset (); |
|
332 SetName(iObexName); |
|
333 iObject->SetNameL (iObexName); |
|
334 iClient->Get(*iObject, iStatus); |
|
335 SetActive(); |
|
336 iState = EGetting; |
|
337 } |
|
338 |
|
339 |
|
340 void CObexClientHandler::GetByTypeL() |
|
341 { |
|
342 if(IsActive()) |
|
343 { |
|
344 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
345 return; |
|
346 } |
|
347 |
|
348 iObject->Reset (); |
|
349 TBuf8<300> buf; |
|
350 buf.Copy(iGetType); |
|
351 buf.Append(0); |
|
352 iObject->SetTypeL (buf); |
|
353 iClient->Get(*iObject, iStatus); |
|
354 SetActive(); |
|
355 iState = EGetting; |
|
356 |
|
357 } |
|
358 |
|
359 void CObexClientHandler::Put(TDes& aFilename) |
|
360 { |
|
361 if(IsActive()) |
|
362 { |
|
363 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
364 return; |
|
365 } |
|
366 |
|
367 TInt err; |
|
368 |
|
369 err = SetUpObject (aFilename); |
|
370 |
|
371 if( err != KErrNone) |
|
372 { |
|
373 iParent->Console()->Printf(_L("\r\n Couldnt set up object : error %d \r\n"),err); |
|
374 return; |
|
375 } |
|
376 |
|
377 // Start the timer. |
|
378 iStartTime.HomeTime(); |
|
379 |
|
380 iClient->Put(*iFileObject,iStatus); |
|
381 SetActive(); |
|
382 iState = EPutting; |
|
383 } |
|
384 |
|
385 void CObexClientHandler::GetReferenceL(TInt aReferenceId) |
|
386 { |
|
387 if(IsActive()) |
|
388 { |
|
389 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
390 return; |
|
391 } |
|
392 iParent->iRefHandler->CreateReferenceL(*iObject, *iObjectBuffer, aReferenceId, iParent->iTransport); |
|
393 iClient->Get(*iObject, iStatus); |
|
394 SetActive(); |
|
395 iState = EGettingReference; |
|
396 } |
|
397 |
|
398 |
|
399 //multiple HTTP packets sent in a single Obex packet |
|
400 void CObexClientHandler::HTTPTest1L() //tam |
|
401 { |
|
402 if(IsActive()) |
|
403 { |
|
404 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
405 return; |
|
406 } |
|
407 |
|
408 iObject->Reset (); |
|
409 SetName(iObexName); |
|
410 iObject->SetNameL (iObexName); |
|
411 |
|
412 //now add in the HTTP headers |
|
413 |
|
414 iObject->AddHttpL(_L8("Test 1 HTTP header 1\r\n")); |
|
415 iObject->AddHttpL(_L8("Test 1 HTTP header 2\r\n")); |
|
416 iObject->AddHttpL(_L8("Test 1 HTTP header 3\r\n")); |
|
417 iObject->AddHttpL(_L8("Test 1 HTTP header 4\r\n")); |
|
418 iObject->AddHttpL(_L8("Test 1 HTTP header 5\r\n")); |
|
419 iObject->AddHttpL(_L8("Test 1 HTTP header 6\r\n")); |
|
420 iObject->AddHttpL(_L8("Test 1 HTTP header 7\r\n")); |
|
421 iObject->AddHttpL(_L8("Test 1 HTTP header 8\r\n")); |
|
422 iObject->AddHttpL(_L8("Test 1 HTTP header 9\r\n")); |
|
423 iObject->AddHttpL(_L8("Test 1 HTTP header 10\r\n")); |
|
424 |
|
425 |
|
426 iClient->Get(*iObject, iStatus); |
|
427 SetActive(); |
|
428 iState = EGetting; |
|
429 } |
|
430 |
|
431 //multiple HHTP packets sent in multiple Obex packets |
|
432 void CObexClientHandler::HTTPTest2L() |
|
433 { |
|
434 |
|
435 |
|
436 TBuf8<520> localBuf; |
|
437 |
|
438 if(IsActive()) |
|
439 { |
|
440 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
441 return; |
|
442 } |
|
443 |
|
444 |
|
445 iObject->Reset (); |
|
446 SetName(iObexName); |
|
447 iObject->SetNameL (iObexName); |
|
448 |
|
449 for ( TUint x = 0; x < 10; x++ ) //should be 10*512 HTTP packets, |
|
450 { // which is in excess of the 4K Tranport size |
|
451 localBuf = _L8("Test 2 HTTP Header"); |
|
452 localBuf.AppendFill(TUint(x + '1'), 500); |
|
453 |
|
454 iObject->AddHttpL(localBuf); |
|
455 } |
|
456 |
|
457 iClient->Get(*iObject, iStatus); |
|
458 SetActive(); |
|
459 iState = EGetting; |
|
460 } |
|
461 |
|
462 //single HHTP packet too large for an Obex packet will not go |
|
463 void CObexClientHandler::HTTPTest3L() |
|
464 { |
|
465 HBufC8* localBuf = HBufC8::NewL(5020); |
|
466 |
|
467 |
|
468 TPtr8 ptr = localBuf->Des(); |
|
469 |
|
470 if(IsActive()) |
|
471 { |
|
472 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
473 return; |
|
474 } |
|
475 |
|
476 iObject->Reset (); |
|
477 SetName(iObexName); |
|
478 iObject->SetNameL (iObexName); |
|
479 |
|
480 |
|
481 ptr = _L8("Test 3 HTTP Header "); |
|
482 ptr.AppendFill(TUint('A'), 5000); |
|
483 |
|
484 iObject->AddHttpL(ptr); |
|
485 |
|
486 |
|
487 iClient->Get(*iObject, iStatus); |
|
488 SetActive(); |
|
489 iState = EGetting; |
|
490 } |
|
491 |
|
492 //a single (too) large HTTP packet, with multiple HTTP packets |
|
493 //large one ignored, multiple smaller should all go |
|
494 void CObexClientHandler::HTTPTest4L() |
|
495 { |
|
496 HBufC8* localBuf = HBufC8::NewL(5020); |
|
497 |
|
498 TPtr8 ptr = localBuf->Des(); |
|
499 if(IsActive()) |
|
500 { |
|
501 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
502 return; |
|
503 } |
|
504 |
|
505 iObject->Reset (); |
|
506 SetName(iObexName); |
|
507 iObject->SetNameL (iObexName); |
|
508 |
|
509 |
|
510 ptr = _L8("Test 4 HTTP header 1"); |
|
511 iObject->AddHttpL(ptr); |
|
512 |
|
513 //now for the excessively large header |
|
514 ptr = _L8("Test 4 HTTP header 2"); |
|
515 ptr.AppendFill(TUint('B'), 5000); |
|
516 iObject->AddHttpL(ptr); |
|
517 |
|
518 //and a reasonable header again |
|
519 |
|
520 ptr = _L8("Test 4 HTTP header 3"); |
|
521 iObject->AddHttpL(ptr); |
|
522 |
|
523 iClient->Get(*iObject, iStatus); |
|
524 SetActive(); |
|
525 iState = EGetting; |
|
526 } |
|
527 |
|
528 |
|
529 void CObexClientHandler::AppParamsTestL() |
|
530 { |
|
531 if(IsActive()) |
|
532 { |
|
533 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
534 return; |
|
535 } |
|
536 |
|
537 iObject->Reset (); |
|
538 SetName(iObexName); |
|
539 iObject->SetNameL (iObexName); |
|
540 |
|
541 TBuf8<40> param; |
|
542 param.Copy(_L("\x04")); |
|
543 param.Append(_L("\x03")); |
|
544 param.Append(_L("App params 123")); |
|
545 iObject->SetAppParamL(param); |
|
546 |
|
547 |
|
548 iClient->Get(*iObject, iStatus); |
|
549 SetActive(); |
|
550 iState = EGetting; |
|
551 |
|
552 |
|
553 } |
|
554 |
|
555 void CObexClientHandler::ChangeAuthenticationChallengeHeaders(TChar aChar) |
|
556 { |
|
557 switch(aChar) |
|
558 { |
|
559 case '1': |
|
560 // Suppress 'Options' |
|
561 iClient->SuppressAuthenticationHeaderElements(CObex::EObexSuppressChallengeOptionsAuthElement); |
|
562 break; |
|
563 case '2': |
|
564 // Suppress 'Realm' |
|
565 iClient->SuppressAuthenticationHeaderElements(CObex::EObexSuppressRealmAuthElement); |
|
566 break; |
|
567 case '3': |
|
568 // Supress both |
|
569 iClient->SuppressAuthenticationHeaderElements(CObex::EObexSuppressAllAuthElements); |
|
570 break; |
|
571 case '4': |
|
572 // Reset to default |
|
573 iClient->SuppressAuthenticationHeaderElements(CObex::EObexNoSuppressedAuthElements); |
|
574 break; |
|
575 case '5': |
|
576 // Invalid enum (magic number) |
|
577 iClient->SuppressAuthenticationHeaderElements(static_cast<CObex::TObexSuppressedAuthElements>(0x08)); |
|
578 break; |
|
579 default: |
|
580 break; |
|
581 } |
|
582 } |
|
583 |
|
584 void CObexClientHandler::PutReferenceL(TInt aReferenceId) |
|
585 { |
|
586 if(IsActive()) |
|
587 { |
|
588 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
589 return; |
|
590 } |
|
591 |
|
592 iParent->iRefHandler->CreateReferenceL(*iObject, *iObjectBuffer, aReferenceId, iParent->iTransport); |
|
593 iClient->Put(*iObject,iStatus); |
|
594 SetActive(); |
|
595 iState = EPuttingReference; |
|
596 } |
|
597 |
|
598 TInt CObexClientHandler::SetUpObject(TDes& filename) |
|
599 { |
|
600 // iFileObject->SetDataFileL(KNullDesC); |
|
601 TRAPD (err, iFileObject->InitFromFileL (filename)); |
|
602 |
|
603 if (err != KErrNone) |
|
604 { |
|
605 RFs fs; |
|
606 RFile f; |
|
607 if ((fs.Connect () != KErrNone) || |
|
608 (f.Create (fs, filename, EFileShareExclusive | EFileWrite) != KErrNone)) |
|
609 iParent->Console()->Printf(_L("\r\nError reading '%s'.\r\nI tried to create this file for you, but failed to do that too. Sorry.\r\n\r\n"), filename.PtrZ ()); |
|
610 else |
|
611 { |
|
612 f.Write (_L8("Test file for sending from EPOC\r\n\r\nLooks like obex is sending OK!!\r\n")); |
|
613 f.Close (); |
|
614 iParent->Console()->Printf(_L("\r\nFile '%s' did not exist, so I've created one.\r\nPlease try again.\r\n\r\n"), filename.PtrZ ()); |
|
615 } |
|
616 fs.Close (); |
|
617 } |
|
618 |
|
619 //iFileObject->SetNameL(iObexName); |
|
620 |
|
621 return err; |
|
622 } |
|
623 |
|
624 |
|
625 void CObexClientHandler::RunL () |
|
626 { |
|
627 if (iStatus != KErrNone) |
|
628 {// Handle error |
|
629 } |
|
630 |
|
631 switch (iState) |
|
632 { |
|
633 case EConnecting: |
|
634 iParent->Console()->Printf(_L("\r\nConnect completed with error code: %d\r\n\r\n"),iStatus.Int()); |
|
635 iState = EConnected;//may not be connected actually |
|
636 break; |
|
637 |
|
638 case EPutting: |
|
639 { |
|
640 TTime finishTime; |
|
641 finishTime.HomeTime(); |
|
642 TTimeIntervalMicroSeconds diff = finishTime.MicroSecondsFrom(iStartTime); |
|
643 |
|
644 iParent->Console()->Printf(_L("\nObject Sent in %d"), diff.Int64()); |
|
645 |
|
646 iState = EConnected; |
|
647 iParent->Console()->Printf(_L("\r\nPut completed with error code: %d\r\n\r\n"),iStatus.Int()); |
|
648 } |
|
649 break; |
|
650 |
|
651 case EGetting: |
|
652 iState = EConnected; |
|
653 iParent->Console()->Printf(_L("\r\nGet completed with error code: %d\r\n\r\n"),iStatus.Int()); |
|
654 DisplayObjectL(); |
|
655 SaveObject(); |
|
656 iObject->Reset (); |
|
657 break; |
|
658 |
|
659 case EGettingReference: |
|
660 { |
|
661 iState = EConnected; |
|
662 iParent->Console()->Printf(_L("\r\nGet completed with error code: %d\r\n\r\n"),iStatus.Int()); |
|
663 if(iStatus == KErrNone) |
|
664 { |
|
665 DisplayObjectL(); |
|
666 TInt objComp = iParent->iRefHandler->CompareObjectToReferenceL(*iObject, *iObjectBuffer, iParent->iTransport); |
|
667 ASSERT(objComp == 0); // Make sure what we sent (the ref obj) matches what we got |
|
668 (void) objComp; // avoid build warning |
|
669 // iParent->Console()->Printf(_L("\r\nReference Object Comparison Result: %d\r\n\r\n"), objComp); |
|
670 iParent->Console()->Printf(_L("\r\nReference Object Comparison OK\r\n\r\n")); |
|
671 } |
|
672 else |
|
673 { |
|
674 iParent->Console()->Printf(_L("GET REFERENCE OBJECT FAILED\n")); |
|
675 } |
|
676 iObject->Reset(); |
|
677 |
|
678 if (iCurrentTestNumber < KMaxNumOfTests) |
|
679 GetReferenceL(++iCurrentTestNumber); |
|
680 else |
|
681 { |
|
682 iParent->Console()->Printf(_L("All GET tests completed\n")); |
|
683 ResetCurrentTestNumber(); |
|
684 } |
|
685 break; |
|
686 } |
|
687 case EPuttingReference: |
|
688 iState = EConnected; |
|
689 iParent->Console()->Printf(_L("\r\nReference Put completed with error code: %d\r\n\r\n"),iStatus.Int()); |
|
690 if(iStatus != KErrNone) |
|
691 { |
|
692 iParent->Console()->Printf(_L("PUT REFERENCE OBJECT FAILED\n")); |
|
693 } |
|
694 if (iCurrentTestNumber < KMaxNumOfTests) |
|
695 PutReferenceL(++iCurrentTestNumber); |
|
696 else |
|
697 { |
|
698 iParent->Console()->Printf(_L("All PUT tests completed\n")); |
|
699 ResetCurrentTestNumber(); |
|
700 } |
|
701 |
|
702 break; |
|
703 |
|
704 case EDisconnecting: |
|
705 iParent->Console()->Printf(_L("\r\nDisconnect completed with error code: %d\r\n\r\n"),iStatus.Int()); |
|
706 iState = EIdle; |
|
707 break; |
|
708 case ESettingPath: |
|
709 iParent->Console()->Printf(_L("\r\nSetPath completed with error code: %d\r\n\r\n"),iStatus.Int()); |
|
710 iState = EConnected; |
|
711 break; |
|
712 default: |
|
713 iParent->Console()->Printf(_L("\r\nTest Code is in an incorrect state: %d\r\n\r\n"),iState); |
|
714 } |
|
715 } |
|
716 |
|
717 void CObexClientHandler::DoCancel() |
|
718 { |
|
719 delete iClient; |
|
720 iClient = NULL; |
|
721 #ifdef ERROR_RESOLUTION_EXTENSION |
|
722 delete iClientErrorResolver; |
|
723 iClientErrorResolver = NULL; |
|
724 #endif // ERROR_RESOLUTION_EXTENSION |
|
725 } |
|
726 |
|
727 void CObexClientHandler::DisplayObjectL() |
|
728 { |
|
729 // Display Contents of CBufFlat data on current console |
|
730 // This size is wrong if we abort, due to size being pre-allocated! DOH! |
|
731 |
|
732 iParent->Console()->Printf(_L("Size of received object = %d\n"),iObjectBuffer->Size()); |
|
733 |
|
734 TInt err = KErrNone; |
|
735 if (iParent->DisplayHeaders()) |
|
736 { |
|
737 CObexHeader* header = CObexHeader::NewL(); |
|
738 CleanupStack::PushL(header); |
|
739 |
|
740 iObject->HeaderSet().SetMask(NULL); |
|
741 iObject->HeaderSet().First(); |
|
742 |
|
743 while (err == KErrNone) |
|
744 { |
|
745 err = iObject->HeaderSet().This(header); |
|
746 |
|
747 switch (header->Type()) |
|
748 { |
|
749 case (0x00): //Unicode |
|
750 { |
|
751 HBufC16* buf = NULL; |
|
752 TRAPD(err, buf = HBufC16::NewL((header->AsUnicode()).Size())); |
|
753 if (err) |
|
754 { |
|
755 iParent->iConsole->Printf(_L("Unicode Header (0x%x)- Error allocating memory to display\r\n"), header->HI()); |
|
756 } |
|
757 else |
|
758 { |
|
759 TPtr16 type(buf->Des()); |
|
760 type.Copy(header->AsUnicode()); |
|
761 |
|
762 iParent->iConsole->Printf(_L("Unicode Header (0x%x) = : \"%S\"\r\n"), header->HI(), &type); |
|
763 } |
|
764 delete buf; |
|
765 break; |
|
766 } |
|
767 case (0x01): // ByteSeq |
|
768 { |
|
769 HBufC16* buf = NULL; |
|
770 TRAPD(err, buf = HBufC16::NewL((header->AsByteSeq()).Size())); |
|
771 if (err) |
|
772 { |
|
773 iParent->iConsole->Printf(_L("ByteSeq Header (0x%x)- Error allocating memory to display\r\n"), header->HI()); |
|
774 } |
|
775 else |
|
776 { |
|
777 TPtr16 type(buf->Des()); |
|
778 type.Copy(header->AsByteSeq()); |
|
779 |
|
780 iParent->iConsole->Printf(_L("ByteSeq Header (0x%x) = : \"%S\"\r\n"), header->HI(), &type); |
|
781 } |
|
782 delete buf; |
|
783 break; |
|
784 } |
|
785 case (0x02): // Byte |
|
786 { |
|
787 iParent->iConsole->Printf(_L("Byte Header (0x%x) = : 0x%x\r\n"), header->HI(), header->AsByte()); |
|
788 break; |
|
789 } |
|
790 case (0x03): //FourByte |
|
791 { |
|
792 iParent->iConsole->Printf(_L("FourByte Header (0x%x) = : 0x%x\r\n"), header->HI(), header->AsFourByte()); |
|
793 break; |
|
794 } |
|
795 default : {break;} |
|
796 } |
|
797 |
|
798 err = iObject->HeaderSet().Next(); |
|
799 } |
|
800 |
|
801 CleanupStack::Pop(header); |
|
802 delete header; |
|
803 } |
|
804 |
|
805 TDateTime dt = iObject->Time().DateTime(); |
|
806 iParent->Console()->Printf(_L("\r\nTimestamp: %d/%d/%d, %d:%d:%d\r\n\r\n"), |
|
807 dt.Day()+1, dt.Month()+1, dt.Year(), dt.Hour(), dt.Minute(), dt.Second()); |
|
808 |
|
809 TBuf8<1024> tempBuffer; |
|
810 // iObjectBuffer->Read(0, tempBuffer, iObjectBuffer->Size()); |
|
811 iObjectBuffer->Read(0, tempBuffer, tempBuffer.MaxSize() < iObjectBuffer->Size() ? tempBuffer.MaxSize() : iObjectBuffer->Size()); |
|
812 // Printf fails with Descriptor bigger than X hundred bytes so write byte at a time |
|
813 for(TInt count = 0; count < tempBuffer.Size(); count++) |
|
814 { |
|
815 iParent->Console()->Printf(_L("%C"),tempBuffer[count]); |
|
816 } |
|
817 } |
|
818 |
|
819 void CObexClientHandler::SaveObject() |
|
820 { |
|
821 |
|
822 TFileName name; |
|
823 TParse parser; |
|
824 TBool bIsFullPath = EFalse; |
|
825 |
|
826 _LIT(KDrive, ""); |
|
827 TBufC<10> drive(KDrive); |
|
828 |
|
829 TPtr pDrive(drive.Des()); |
|
830 |
|
831 TInt ret = parser.Set(iObject->Name() ,0,0); |
|
832 |
|
833 if(KErrNone == ret) |
|
834 { |
|
835 pDrive = parser.Drive(); |
|
836 |
|
837 if(pDrive.Length() != 0) // if == 0, relative path |
|
838 { |
|
839 bIsFullPath = ETrue; |
|
840 } |
|
841 } |
|
842 // the case ret != KErrNone is kept for legacy purpose, TODO cope with return codes |
|
843 |
|
844 if(!bIsFullPath) |
|
845 { |
|
846 name = iParent->iInboxRoot; |
|
847 } |
|
848 |
|
849 name.Append(iObject->Name()); |
|
850 |
|
851 TInt err = iObject->WriteToFile(name); |
|
852 if (err == KErrAlreadyExists) |
|
853 { |
|
854 iParent->Console()->Printf(_L("\r\nWrite failed, File Already Exists\n")); |
|
855 } |
|
856 } |
|
857 |
|
858 |
|
859 void CObexClientHandler::SetPath() |
|
860 { |
|
861 if(IsActive()) |
|
862 { |
|
863 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
864 return; |
|
865 } |
|
866 |
|
867 CObex::TSetPathInfo info; |
|
868 iParent->Console()->Printf(_L("Please enter path name ('..' = parent, '!' = Create, ' ' = empty name):\n")); |
|
869 info.iNamePresent = ETrue; |
|
870 SetName(info.iName); |
|
871 info.iFlags |= 2; // Set "Don't Create" flag as default. |
|
872 |
|
873 // Parent |
|
874 if (info.iName.Length() >= 2 && info.iName[0] == '.' && info.iName[1] == '.') |
|
875 { |
|
876 info.iName.Delete(0, 2); |
|
877 info.iFlags |= 1; |
|
878 } |
|
879 // Create |
|
880 if (info.iName.Length() >= 1 && info.iName[0] == '!') |
|
881 { |
|
882 info.iName.Delete(0, 1); |
|
883 info.iFlags &= ~(2); // Clear the "Don't Create" bit |
|
884 } |
|
885 // Empty Name |
|
886 if (info.iName.Length() >= 1 && info.iName[0] == ' ') |
|
887 { |
|
888 info.iName.Delete(0, 1); |
|
889 } |
|
890 else if (info.iName.Length() <= 0) |
|
891 info.iNamePresent = EFalse; |
|
892 iClient->SetPath(info,iStatus); |
|
893 SetActive(); |
|
894 iState = ESettingPath; |
|
895 } |
|
896 |
|
897 void CObexClientHandler::SetObexName() |
|
898 { |
|
899 SetName(iObexName); |
|
900 } |
|
901 |
|
902 void CObexClientHandler::SetType() |
|
903 { |
|
904 iParent->Console()->Printf(_L("\nEnter Mime type, or 1 for text/x-vcard, 2 for x-obex/folder-listing")); |
|
905 SetName(iGetType); |
|
906 if (iGetType == _L("1")) |
|
907 iGetType = _L("text/x-vcard"); |
|
908 else if (iGetType == _L("2")) |
|
909 iGetType = _L("x-obex/folder-listing"); |
|
910 } |
|
911 |
|
912 |
|
913 void CObexClientHandler::SetName(TDes& aName) |
|
914 { |
|
915 TBuf<64> oldName; |
|
916 oldName = aName; |
|
917 |
|
918 TKeyCode aCode; |
|
919 TBuf<1> aChar; |
|
920 iParent->Console()->Printf(_L("\nEnter a name: %S"),&aName); |
|
921 FOREVER |
|
922 { |
|
923 aCode = iParent->Console()->Getch(); |
|
924 aChar.SetLength(0); |
|
925 aChar.Append(aCode); |
|
926 |
|
927 iParent->Console()->Printf(_L("%S"),&aChar); |
|
928 |
|
929 // If <CR> finish editing string |
|
930 if (aCode == EKeyEnter) |
|
931 break; |
|
932 |
|
933 // if <BS> remove last character |
|
934 if ((aCode == EKeyBackspace)&&(aName.Length() != 0)) |
|
935 aName.SetLength((aName.Length()-1)); |
|
936 else |
|
937 aName.Append(aCode); |
|
938 } |
|
939 iParent->Console()->Printf(_L("\n")); |
|
940 // if (aName.Length()>0) |
|
941 // iParent->Console()->Printf( _L("\n name size = %d\n"),aName.Length()); |
|
942 // else |
|
943 // { |
|
944 // iParent->Console()->Printf(_L("\nERROR: name of length zero, name unchanged!\n"),aName.Length()); |
|
945 // aName = oldName; |
|
946 // } |
|
947 |
|
948 } |
|
949 |
|
950 void CObexClientHandler::ConnectWithAuthenticationL() |
|
951 { |
|
952 if(IsActive()) |
|
953 { |
|
954 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
955 return; |
|
956 } |
|
957 |
|
958 iClient->ConnectL(iChallengePassword, iStatus); |
|
959 SetActive(); |
|
960 iState = EConnecting; |
|
961 } |
|
962 |
|
963 void CObexClientHandler::ConnectWithTarget() |
|
964 { |
|
965 if(IsActive()) |
|
966 { |
|
967 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
968 return; |
|
969 } |
|
970 iClient->Connect(*iTargetHeaderObject, iStatus); |
|
971 SetActive(); |
|
972 iState = EConnecting; |
|
973 } |
|
974 |
|
975 void CObexClientHandler::ConnectWithAuthenticationAndTargetL() |
|
976 { |
|
977 if(IsActive()) |
|
978 { |
|
979 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
980 return; |
|
981 } |
|
982 iClient->ConnectL(*iTargetHeaderObject, iChallengePassword, iStatus); |
|
983 SetActive(); |
|
984 iState = EConnecting; |
|
985 } |
|
986 |
|
987 |
|
988 void CObexClientHandler::EnablePassword() |
|
989 { |
|
990 iClient->SetCallBack(*this); |
|
991 } |
|
992 |
|
993 void CObexClientHandler::ChangeChallengePassword() |
|
994 { |
|
995 iParent->SetPassword(iChallengePassword); |
|
996 } |
|
997 |
|
998 void CObexClientHandler::SetCommandTimeout() |
|
999 { |
|
1000 TUint timeout = 0; |
|
1001 if (iParent->SetNumber(timeout)) |
|
1002 { |
|
1003 const TTimeIntervalMicroSeconds32 temp = timeout; |
|
1004 iClient->CObexClient::SetCommandTimeOut(temp); |
|
1005 iParent->Console()->Printf(_L("\r\nCommand Sucessful\r\n")); |
|
1006 } |
|
1007 } |
|
1008 |
|
1009 void CObexClientHandler::ChangeResponsePassword() |
|
1010 { |
|
1011 iParent->Cancel(); |
|
1012 iParent->SetPassword(iResponsePassword); |
|
1013 iParent->RequestCharacter(); |
|
1014 } |
|
1015 |
|
1016 void CObexClientHandler::GetUserPasswordL(const TDesC& aUserID) |
|
1017 { |
|
1018 iParent->Console()->Printf(_L("\r\nClient has been challenged by %S"), &aUserID); |
|
1019 ChangeResponsePassword(); //get the password from user |
|
1020 // iParent->Console()->Printf(_L("\r\nUser Password requested for %S"), &aUserID); |
|
1021 iClient->UserPasswordL(iResponsePassword); |
|
1022 } |
|
1023 |
|
1024 #ifdef ERROR_RESOLUTION_EXTENSION |
|
1025 void CObexClientHandler::LastError() |
|
1026 { |
|
1027 if (iClientErrorResolver == NULL) |
|
1028 { |
|
1029 iParent->Console()->Printf(_L("Client not started\r\n")); |
|
1030 } |
|
1031 else |
|
1032 { |
|
1033 switch (iClientErrorResolver->LastError()) |
|
1034 { |
|
1035 case EObexNoExtendedError: |
|
1036 { |
|
1037 iParent->Console()->Printf(_L("No extended error\r\n")); |
|
1038 } |
|
1039 break; |
|
1040 case EObexRequestAccepted: |
|
1041 { |
|
1042 iParent->Console()->Printf(_L("Request accepted\r\n")); |
|
1043 } |
|
1044 break; |
|
1045 case EObexRequestNotAccepted: |
|
1046 { |
|
1047 iParent->Console()->Printf(_L("Request not accepted\r\n")); |
|
1048 } |
|
1049 break; |
|
1050 case EObexRequestTimeout: |
|
1051 { |
|
1052 iParent->Console()->Printf(_L("Request timeout\r\n")); |
|
1053 } |
|
1054 break; |
|
1055 case EObexRequestLocalInterruption: |
|
1056 { |
|
1057 iParent->Console()->Printf(_L("Request local interruption\r\n")); |
|
1058 } |
|
1059 break; |
|
1060 case EObexRequestLinkInterruption: |
|
1061 { |
|
1062 iParent->Console()->Printf(_L("Request link interruption\r\n")); |
|
1063 } |
|
1064 break; |
|
1065 default: |
|
1066 { |
|
1067 iParent->Console()->Printf(_L("Last Error value returned from client not recognised\r\n")); |
|
1068 } |
|
1069 } |
|
1070 } |
|
1071 } |
|
1072 #endif // ERROR_RESOLUTION_EXTENSION |
|
1073 |
|
1074 #ifdef EMPTY_HEADERS_TEST |
|
1075 void CObexClientHandler::EmptyHeaderTestL(TPtrC aName, TPtrC8 aType, TPtrC aDesc, TPtrC8 aTarget, TPtrC8 aAppParam) |
|
1076 { |
|
1077 if(IsActive()) |
|
1078 { |
|
1079 iParent->Console()->Printf(_L("\r\nError: Client handler already active\r\n")); |
|
1080 return; |
|
1081 } |
|
1082 iObexEmptyHeaderTest->SetHeadersL(aName, aType, aDesc, aTarget, aAppParam); |
|
1083 iClient->Put(*(iObexEmptyHeaderTest->ObexObject()),iStatus); |
|
1084 SetActive(); |
|
1085 iState = EPutting; |
|
1086 } |
|
1087 #endif //EMPTY_HEADERS_TEST |