|
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 "serverhandlerbase.h" |
|
22 #include "TOBEXCON.H" |
|
23 #include "btextnotifiers.h" |
|
24 #include "serverasyncao.h" |
|
25 #include <obexconstants.h> |
|
26 #include <obexbttransportinfo.h> |
|
27 #include <obexirtransportinfo.h> |
|
28 #include "obexconstantsinternal.h" |
|
29 |
|
30 #include "serverpacketaccessui.h" |
|
31 |
|
32 CObexServerHandlerBase::CObexServerHandlerBase(CActiveConsole* aParent) |
|
33 : iAcceptPuts(ETrue), iParent(aParent) |
|
34 { |
|
35 } |
|
36 |
|
37 |
|
38 void CObexServerHandlerBase::BaseConstructL(TTransport aTransport) |
|
39 { |
|
40 |
|
41 iTransportLayer = aTransport; |
|
42 switch (aTransport) |
|
43 { |
|
44 case (EBluetooth): |
|
45 InitBluetoothL(); |
|
46 break; |
|
47 |
|
48 case (EIrda): |
|
49 { |
|
50 if(iParent->UseIrdaNickname()) |
|
51 { |
|
52 TObexIrV3TransportInfo aInfo; |
|
53 aInfo.iTransportName = KObexIrTTPProtocolV3; |
|
54 aInfo.iReceiveMtu = iParent->iRecvMTU; |
|
55 aInfo.iTransmitMtu = iParent->iTransmitMTU; |
|
56 aInfo.iAddr.SetPort(KAutoBindLSAP);//default obex server for now |
|
57 _LIT8(KClassName, "OBEX"); |
|
58 _LIT8(KAttributeName, "IrDA:TinyTP:LsapSel"); |
|
59 aInfo.iClassName = KClassName; |
|
60 aInfo.iAttributeName = KAttributeName; |
|
61 aInfo.iDiscoverySlots = iParent->iDiscoverySlots; |
|
62 aInfo.iDiscoveryAttempts = iParent->iDiscoveryAttempts; |
|
63 aInfo.iLocalDeviceNickname = iParent->GetIrdaNickname(); |
|
64 aInfo.iLocalDeviceNicknameValid = ETrue; |
|
65 iServer = CObexServer::NewL(aInfo); |
|
66 } |
|
67 else |
|
68 { |
|
69 TObexIrV2TransportInfo aInfo; |
|
70 aInfo.iTransportName = KObexIrTTPProtocolV2; |
|
71 aInfo.iReceiveMtu = iParent->iRecvMTU; |
|
72 aInfo.iTransmitMtu = iParent->iTransmitMTU; |
|
73 aInfo.iAddr.SetPort(KAutoBindLSAP);//default obex server for now |
|
74 _LIT8(KClassName, "OBEX"); |
|
75 _LIT8(KAttributeName, "IrDA:TinyTP:LsapSel"); |
|
76 aInfo.iClassName = KClassName; |
|
77 aInfo.iAttributeName = KAttributeName; |
|
78 aInfo.iDiscoverySlots = iParent->iDiscoverySlots; |
|
79 aInfo.iDiscoveryAttempts = iParent->iDiscoveryAttempts; |
|
80 iServer = CObexServer::NewL(aInfo); |
|
81 } |
|
82 User::LeaveIfError(iServer->Start(this)); |
|
83 |
|
84 /* // Uncomment this code to demonstrate CObexServer::TransportInfo |
|
85 // API with TTP transport. |
|
86 // We get back an TObexIrTransportInfo because we asked for KObexIrTTPProtocol. |
|
87 const TObexIrTransportInfo* transportInfo = static_cast<const TObexIrTransportInfo*>(iServer->TransportInfo()); |
|
88 iParent->Console()->Printf(_L("Transport info: \r\n")); |
|
89 iParent->Console()->Printf(_L("\ttransport name: %S\r\n"), &transportInfo->iTransportName); |
|
90 iParent->Console()->Printf(_L("\tversion: %d\r\n"), transportInfo->iVersion); |
|
91 iParent->Console()->Printf(_L("\treceive MTU: %d\r\n"), transportInfo->iReceiveMtu); |
|
92 iParent->Console()->Printf(_L("\ttransmitMTU: %d\r\n"), transportInfo->iTransmitMtu); |
|
93 iParent->Console()->Printf(_L("\tTinyTP port: 0x%02x\r\n"), transportInfo->iAddr.Port()); |
|
94 TName wide; |
|
95 wide.Copy(transportInfo->iClassName); |
|
96 iParent->Console()->Printf(_L("\tclass name: %S\r\n"), &wide); |
|
97 wide.Copy(transportInfo->iAttributeName); |
|
98 iParent->Console()->Printf(_L("\tattribute name: %S\r\n"), &wide); |
|
99 */ |
|
100 break; |
|
101 } |
|
102 |
|
103 case (EUsb): |
|
104 { |
|
105 TObexUsbProtocolInfo info; |
|
106 info.iTransport = KObexUsbProtocol; |
|
107 info.iInterfaceStringDescriptor = _L("TOBEX Server Interface"); |
|
108 |
|
109 iServer = CObexServer::NewL (info); |
|
110 User::LeaveIfError(iServer->Start (this)); |
|
111 |
|
112 /* // Uncomment this code to demonstrate CObexServer::TransportInfo |
|
113 // API with USB transport. |
|
114 // We get back an TObexUsbTransportInfo because we asked for KObexUsbProtocol. |
|
115 const TObexUsbTransportInfo* transportInfo = static_cast<const TObexUsbTransportInfo*>(iServer->TransportInfo()); |
|
116 iParent->Console()->Printf(_L("Transport info: \r\n")); |
|
117 iParent->Console()->Printf(_L("\ttransport name: %S\r\n"), &transportInfo->iTransportName); |
|
118 iParent->Console()->Printf(_L("\tversion: %d\r\n"), transportInfo->iVersion); |
|
119 iParent->Console()->Printf(_L("\treceive MTU: %d\r\n"), transportInfo->iReceiveMtu); |
|
120 iParent->Console()->Printf(_L("\ttransmitMTU: %d\r\n"), transportInfo->iTransmitMtu); |
|
121 iParent->Console()->Printf(_L("\tinterface string desc: %S\r\n"), &transportInfo->iInterfaceStringDescriptor); |
|
122 */ |
|
123 break; |
|
124 } |
|
125 |
|
126 case (EWin32Usb): |
|
127 { |
|
128 TObexUsbProtocolInfo aInfo; |
|
129 aInfo.iTransport = _L("Win32Usb"); |
|
130 aInfo.iInterfaceStringDescriptor = _L("TOBEX Server Interface"); |
|
131 |
|
132 iServer = CObexServer::NewL (aInfo); |
|
133 User::LeaveIfError(iServer->Start (this)); |
|
134 |
|
135 /* // Uncomment this code to demonstrate CObexServer::TransportInfo |
|
136 // API with Win32USB transport. |
|
137 // We get back an TObexUsbTransportInfo because we asked for KObexUsbProtocol. |
|
138 const TObexUsbTransportInfo* transportInfo = static_cast<const TObexUsbTransportInfo*>(iServer->TransportInfo()); |
|
139 iParent->Console()->Printf(_L("Transport info: \r\n")); |
|
140 iParent->Console()->Printf(_L("\ttransport name: %S\r\n"), &transportInfo->iTransportName); |
|
141 iParent->Console()->Printf(_L("\tversion: %d\r\n"), transportInfo->iVersion); |
|
142 iParent->Console()->Printf(_L("\treceive MTU: %d\r\n"), transportInfo->iReceiveMtu); |
|
143 iParent->Console()->Printf(_L("\ttransmitMTU: %d\r\n"), transportInfo->iTransmitMtu); |
|
144 iParent->Console()->Printf(_L("\tinterface string desc: %S\r\n"), &transportInfo->iInterfaceStringDescriptor); |
|
145 */ |
|
146 break; |
|
147 } |
|
148 } |
|
149 |
|
150 #ifdef ASYNC_INDICATION |
|
151 iServerAsyncAO = CServerAsyncAO::NewL(*iServer); |
|
152 #endif |
|
153 } |
|
154 |
|
155 void CObexServerHandlerBase::InitBluetoothL() |
|
156 { |
|
157 TBTServiceSecurity serv; |
|
158 serv.SetUid(KObexTestUid); |
|
159 |
|
160 // UPF - change security here for Bluetooth security testing |
|
161 serv.SetAuthentication(EFalse); |
|
162 serv.SetAuthorisation(EFalse); |
|
163 serv.SetEncryption(EFalse); |
|
164 |
|
165 // now set up Obex... |
|
166 TObexBluetoothProtocolInfo info; |
|
167 info.iTransport = KObexRfcommProtocol; |
|
168 info.iAddr.SetPort(KRfcommPassiveAutoBind); |
|
169 info.iAddr.SetSecurity(serv); |
|
170 |
|
171 TObexProtocolPolicy policy; |
|
172 policy.SetReceiveMtu(iParent->iRecvMTU); |
|
173 policy.SetTransmitMtu(iParent->iTransmitMTU); |
|
174 |
|
175 iServer = CObexServer::NewL(info, policy); |
|
176 iServer->SetReadActivityObserver(this); |
|
177 |
|
178 User::LeaveIfError(iServer->Start (this)); |
|
179 // We get back an TObexBtTransportInfo because we asked for KObexRfcommProtocol. |
|
180 const TObexBtTransportInfo* transportInfo = static_cast<const TObexBtTransportInfo*>(iServer->TransportInfo()); |
|
181 iParent->Console()->Printf(_L("Transport info: \r\n")); |
|
182 iParent->Console()->Printf(_L("\ttransport name: %S\r\n"), &transportInfo->iTransportName); |
|
183 iParent->Console()->Printf(_L("\tversion: %d\r\n"), transportInfo->iVersion); |
|
184 iParent->Console()->Printf(_L("\treceive MTU: %d\r\n"), transportInfo->iReceiveMtu); |
|
185 iParent->Console()->Printf(_L("\ttransmitMTU: %d\r\n"), transportInfo->iTransmitMtu); |
|
186 iParent->Console()->Printf(_L("\tRFCOMM port: 0x%02x\r\n"), transportInfo->iAddr.Port()); |
|
187 |
|
188 // SDP registration |
|
189 User::LeaveIfError(iSdp.Connect()); |
|
190 User::LeaveIfError(iSdpdb.Open(iSdp)); |
|
191 |
|
192 TSdpServRecordHandle handle; |
|
193 iSdpdb.CreateServiceRecordL(TUUID(0x1105), handle); |
|
194 iSdpdb.UpdateAttributeL(handle, 0x100, _L8("Obex push server")); |
|
195 |
|
196 |
|
197 TSdpServRecordHandle ftphandle; |
|
198 iSdpdb.CreateServiceRecordL(TUUID(0x1106), ftphandle); |
|
199 iSdpdb.UpdateAttributeL(ftphandle, 0x100, _L8("File transfer server")); |
|
200 |
|
201 // Protocol Descriptor List (same for both profiles) |
|
202 iProtDescList = CSdpAttrValueDES::NewDESL(0); |
|
203 |
|
204 iProtDescList |
|
205 ->StartListL() |
|
206 ->BuildDESL() |
|
207 ->StartListL() |
|
208 ->BuildUUIDL(TUUID(TUint16(0x0100))) // L2CAP |
|
209 ->EndListL() |
|
210 ->BuildDESL() |
|
211 ->StartListL() |
|
212 ->BuildUUIDL(TUUID(TUint16(0x0003))) // RFCOMM |
|
213 ->BuildUintL(TSdpIntBuf<TInt8>(transportInfo->iAddr.Port())) |
|
214 ->EndListL() |
|
215 ->BuildDESL() |
|
216 ->StartListL() |
|
217 ->BuildUUIDL(TUUID(TUint16(0x0008))) // OBEX |
|
218 ->EndListL() |
|
219 ->EndListL(); |
|
220 |
|
221 iSdpdb.UpdateAttributeL(handle, 4, *iProtDescList); |
|
222 iSdpdb.UpdateAttributeL(ftphandle, 4, *iProtDescList); // put into both records |
|
223 delete iProtDescList; |
|
224 iProtDescList = NULL; |
|
225 |
|
226 // Supported formats list (OPP only) |
|
227 iProtDescList = CSdpAttrValueDES::NewDESL(0); |
|
228 |
|
229 iProtDescList->StartListL() |
|
230 ->BuildUintL(TSdpIntBuf<TUint8>(0xFF)) // Accept any type of object |
|
231 ->EndListL(); |
|
232 |
|
233 iSdpdb.UpdateAttributeL(handle, 0x0303, *iProtDescList); |
|
234 |
|
235 delete iProtDescList; |
|
236 iProtDescList = NULL; |
|
237 |
|
238 // Add OPP to the supported profiles list |
|
239 iProtDescList = CSdpAttrValueDES::NewDESL(0); |
|
240 |
|
241 iProtDescList->StartListL() |
|
242 ->BuildDESL() |
|
243 ->StartListL() |
|
244 ->BuildUUIDL(TUUID(0x1105)) // OPP Profile |
|
245 ->BuildUintL(TSdpIntBuf<TUint16>(0x0100)) // Profile version |
|
246 ->EndListL() |
|
247 ->EndListL(); |
|
248 |
|
249 iSdpdb.UpdateAttributeL(handle, 9, *iProtDescList); // profile list |
|
250 |
|
251 delete iProtDescList; |
|
252 iProtDescList = NULL; |
|
253 |
|
254 // Add FTP to the supported profiles list |
|
255 iProtDescList = CSdpAttrValueDES::NewDESL(0); |
|
256 |
|
257 iProtDescList->StartListL() |
|
258 ->BuildDESL() |
|
259 ->StartListL() |
|
260 ->BuildUUIDL(TUUID(0x1106)) // FTP Profile |
|
261 ->BuildUintL(TSdpIntBuf<TUint16>(0x0100)) // Profile version |
|
262 ->EndListL() |
|
263 ->EndListL(); |
|
264 |
|
265 iSdpdb.UpdateAttributeL(ftphandle, 9, *iProtDescList); // profile list |
|
266 |
|
267 delete iProtDescList; |
|
268 iProtDescList = NULL; |
|
269 |
|
270 // Set host name |
|
271 RSocketServ ss; |
|
272 ss.Connect(); |
|
273 |
|
274 RHostResolver hr; |
|
275 User::LeaveIfError(hr.Open(ss,KBTAddrFamily,KBTLinkManager)); |
|
276 User::LeaveIfError(hr.SetHostName(_L("Symbian Push Server"))); |
|
277 ss.Close(); |
|
278 |
|
279 // Enable enquiry and page scan |
|
280 User::LeaveIfError(RProperty::Set(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothSetScanningStatus, EInquiryAndPageScan)); |
|
281 } |
|
282 |
|
283 CObexServerHandlerBase::~CObexServerHandlerBase () |
|
284 { |
|
285 Stop(); |
|
286 |
|
287 if (iTransportLayer == EBluetooth) |
|
288 { |
|
289 // security now cleared with socket closure |
|
290 iSdpdb.Close(); |
|
291 iSdp.Close(); |
|
292 } |
|
293 #ifdef PACKET_ACCESS_EXTENSION |
|
294 delete iPacketAccessUi; |
|
295 #endif // PACKET_ACCESS_EXTENSION |
|
296 |
|
297 #ifdef ASYNC_INDICATION |
|
298 delete iServerAsyncAO; |
|
299 #endif |
|
300 delete iServer; |
|
301 delete iProtDescList; |
|
302 } |
|
303 |
|
304 void CObexServerHandlerBase::RemoteAddress() |
|
305 { |
|
306 TSockAddr aAddr; |
|
307 iServer->RemoteAddr( aAddr); |
|
308 TBTDevAddr addr = static_cast <TBTSockAddr>(aAddr).BTAddr(); |
|
309 |
|
310 TChar aChar; |
|
311 |
|
312 iParent->Console()->Printf(_L("Remote Address = ")); |
|
313 for(TInt count = 0; count < addr.Des().Length(); count++) |
|
314 { |
|
315 aChar = (addr.Des()[count] & 0xf0)>>4; |
|
316 if (aChar <= 9) |
|
317 aChar += 0x30; |
|
318 else if ((aChar >= 0x0a) && (aChar <= 0x0f)) |
|
319 aChar += 'A' - 0x0a; |
|
320 iParent->Console()->Printf(_L("%C"),(TUint)aChar); |
|
321 |
|
322 aChar = (addr.Des()[count] & 0x0f); |
|
323 if (aChar <= 9) |
|
324 aChar += 0x30; |
|
325 else if ((aChar >= 0x0a) && (aChar <= 0x0f)) |
|
326 aChar += 'A' - 0x0a; |
|
327 iParent->Console()->Printf(_L("%C"),(TUint)aChar); |
|
328 } |
|
329 iParent->Console()->Printf(_L("\r\n")); |
|
330 } |
|
331 |
|
332 |
|
333 void CObexServerHandlerBase::Start() |
|
334 { |
|
335 if (iServer) |
|
336 { |
|
337 iServer->Start(this); |
|
338 } |
|
339 } |
|
340 |
|
341 void CObexServerHandlerBase::Stop() |
|
342 { |
|
343 if (iServer) |
|
344 { |
|
345 iServer->Stop(); |
|
346 } |
|
347 } |
|
348 |
|
349 void CObexServerHandlerBase::SetTargetChecking(CObexServer::TTargetChecking aValue) |
|
350 { |
|
351 iServer->SetTargetChecking(aValue); |
|
352 } |
|
353 |
|
354 |
|
355 |
|
356 // MObexServerNotify interface functions |
|
357 |
|
358 void CObexServerHandlerBase::ErrorIndication (TInt aError) |
|
359 { |
|
360 iParent->Console()->Printf(_L("Obex Server Error: %d\r\n"), aError); |
|
361 } |
|
362 |
|
363 void CObexServerHandlerBase::TransportUpIndication () |
|
364 { |
|
365 iParent->Console()->Printf(_L("\r\nTransport layer now connected\r\n\r\n")); |
|
366 } |
|
367 |
|
368 void CObexServerHandlerBase::TransportDownIndication () |
|
369 { |
|
370 iParent->Console()->Printf(_L("\r\nTransport layer has gone down\r\n\r\n")); |
|
371 |
|
372 if (iObject) |
|
373 { |
|
374 if(!iObject->BytesReceived()) |
|
375 { |
|
376 return; |
|
377 } |
|
378 |
|
379 iParent->Console()->Printf(_L("\r\nWe have received part of an Obex object\r\n\r\n")); |
|
380 |
|
381 iObject->Reset();//close file handle |
|
382 } |
|
383 } |
|
384 #ifdef ASYNC_INDICATION |
|
385 void CObexServerHandlerBase::ObexConnectIndication(const TObexConnectInfo& aRemoteInfo, const TDesC8& /*aInfo*/) |
|
386 #else |
|
387 TInt CObexServerHandlerBase::ObexConnectIndication(const TObexConnectInfo& aRemoteInfo, const TDesC8& /*aInfo*/) |
|
388 #endif |
|
389 { |
|
390 iParent->Console()->Printf(_L("\r\nCObexServerHandler::ObexConnectIndication")); |
|
391 iParent->Console()->Printf(_L("\r\nConnected to machine with OBEX version %d.%d\r\n"), |
|
392 aRemoteInfo.VersionMajor (), aRemoteInfo.VersionMinor ()); |
|
393 |
|
394 if ( aRemoteInfo.iWho.Length() > 0 ) |
|
395 { |
|
396 iParent->Console()->Printf(_L("EWho received from remote side =")); |
|
397 |
|
398 for(TInt count = 0; count < aRemoteInfo.iWho.Length(); count++) |
|
399 { |
|
400 |
|
401 TChar aChar; |
|
402 |
|
403 aChar = (aRemoteInfo.iWho[count] & 0xf0)>>4; |
|
404 if (aChar <= 9) |
|
405 aChar += 0x30; |
|
406 else if ((aChar >= 0x0a) && (aChar <= 0x0f)) |
|
407 aChar += 'A' - 0x0a; |
|
408 iParent->Console()->Printf(_L("%C"),(TUint)aChar); |
|
409 |
|
410 aChar = (aRemoteInfo.iWho[count] & 0x0f); |
|
411 if (aChar <= 9) |
|
412 aChar += 0x30; |
|
413 else if ((aChar >= 0x0a) && (aChar <= 0x0f)) |
|
414 aChar += 'A' - 0x0a; |
|
415 iParent->Console()->Printf(_L("%C"),(TUint)aChar); |
|
416 |
|
417 } |
|
418 iParent->Console()->Printf(_L("\r\n")); |
|
419 } |
|
420 else |
|
421 iParent->Console()->Printf(_L("No Who Header received\r\n")); |
|
422 |
|
423 if ( aRemoteInfo.iTargetHeader.Length() > 0 ) |
|
424 { |
|
425 iParent->Console()->Printf(_L("ETarget received from remote side =")); |
|
426 for(TInt count = 0; count < aRemoteInfo.iTargetHeader.Length(); count++) |
|
427 { |
|
428 TChar aChar; |
|
429 |
|
430 aChar = (aRemoteInfo.iTargetHeader[count] & 0xf0)>>4; |
|
431 if (aChar <= 9) |
|
432 aChar += 0x30; |
|
433 else if ((aChar >= 0x0a) && (aChar <= 0x0f)) |
|
434 aChar += 'A' - 0x0a; |
|
435 iParent->Console()->Printf(_L("%C"),(TUint)aChar); |
|
436 |
|
437 aChar = (aRemoteInfo.iTargetHeader[count] & 0x0f); |
|
438 if (aChar <= 9) |
|
439 aChar += 0x30; |
|
440 else if ((aChar >= 0x0a) && (aChar <= 0x0f)) |
|
441 aChar += 'A' - 0x0a; |
|
442 iParent->Console()->Printf(_L("%C"),(TUint)aChar); |
|
443 } |
|
444 iParent->Console()->Printf(_L("\r\n")); |
|
445 } |
|
446 else |
|
447 iParent->Console()->Printf(_L("No Target Header received\r\n")); |
|
448 |
|
449 #ifndef ASYNC_INDICATION |
|
450 return KErrNone; |
|
451 #endif |
|
452 } |
|
453 |
|
454 void CObexServerHandlerBase::ObexDisconnectIndication (const TDesC8& /*aInfo*/) |
|
455 { |
|
456 iParent->Console()->Printf(_L("\r\nObex Disconnected\r\n\r\n")); |
|
457 } |
|
458 |
|
459 #ifdef ASYNC_INDICATION |
|
460 void CObexServerHandlerBase::PutRequestIndication () |
|
461 #else |
|
462 CObexBufObject* CObexServerHandlerBase::PutRequestIndication () |
|
463 #endif |
|
464 { |
|
465 iStartTime.HomeTime(); |
|
466 |
|
467 iParent->Console()->Printf(_L("Receiving object...\r\n")); |
|
468 iObject->Reset (); |
|
469 #ifdef ASYNC_INDICATION |
|
470 iServerAsyncAO->RequestIndication(CObex::EOpPut, iAcceptPuts?iObject:NULL); |
|
471 #else |
|
472 return iAcceptPuts?iObject:NULL; |
|
473 #endif |
|
474 } |
|
475 |
|
476 TInt CObexServerHandlerBase::PutPacketIndication () |
|
477 { |
|
478 // Only output % received if performance logging is disabled. |
|
479 if(!iParent->iPerformanceLoggingEnabled) |
|
480 { |
|
481 TUint length = iObject->Length(); |
|
482 TUint received = iObject->BytesReceived(); |
|
483 TUint8 percent = 0; |
|
484 if (length > 0) |
|
485 { |
|
486 percent = TUint8((100 * received) / length); |
|
487 iParent->Console()->Printf(_L("\r%d %% "), percent); |
|
488 } |
|
489 else |
|
490 { |
|
491 iParent->Console()->Printf(_L("\r%d Bytes "), iObject->BytesReceived ()); |
|
492 } |
|
493 } |
|
494 return (KErrNone); |
|
495 } |
|
496 |
|
497 #ifdef ASYNC_INDICATION |
|
498 void CObexServerHandlerBase::PutCompleteIndication() |
|
499 #else |
|
500 TInt CObexServerHandlerBase::PutCompleteIndication() |
|
501 #endif |
|
502 { |
|
503 TTime finishTime; |
|
504 finishTime.HomeTime(); |
|
505 TTimeIntervalMicroSeconds diff = finishTime.MicroSecondsFrom(iStartTime); |
|
506 |
|
507 iParent->Console()->Printf(_L("\nObject Received in %d"), diff.Int64()); |
|
508 |
|
509 TPtrC name=iObject->Name(); |
|
510 TBuf<100> type; |
|
511 type.Copy(iObject->Type()); |
|
512 iParent->Console()->Printf(_L("\r\nSuccessfully received '%S'\r\nType[%d]: '%S'\r\n"), &name, type.Length(), &type); |
|
513 |
|
514 TInt err = KErrNone; |
|
515 if (iParent->DisplayHeaders()) |
|
516 { |
|
517 // No need to put header on the cleanup stack, as there are no leaving functions during its lifetime |
|
518 CObexHeader* header = NULL; |
|
519 TRAP(err, header = CObexHeader::NewL()); |
|
520 if (err) |
|
521 { |
|
522 iParent->iConsole->Printf(_L("Error allocating memory to display\r\n")); |
|
523 } |
|
524 |
|
525 iObject->HeaderSet().SetMask(NULL); |
|
526 iObject->HeaderSet().First(); |
|
527 |
|
528 while (err == KErrNone) |
|
529 { |
|
530 err = iObject->HeaderSet().This(header); |
|
531 |
|
532 switch (header->Type()) |
|
533 { |
|
534 case (0x00): //Unicode |
|
535 { |
|
536 HBufC16* buf = NULL; |
|
537 TRAPD(headerErr, buf = HBufC16::NewL((header->AsUnicode()).Size())); |
|
538 if (headerErr) |
|
539 { |
|
540 iParent->iConsole->Printf(_L("Unicode Header (0x%x)- Error allocating memory to display\r\n"), header->HI()); |
|
541 } |
|
542 else |
|
543 { |
|
544 TPtr16 type(buf->Des()); |
|
545 type.Copy(header->AsUnicode()); |
|
546 |
|
547 iParent->iConsole->Printf(_L("Unicode Header (0x%x) = : \"%S\"\r\n"), header->HI(), &type); |
|
548 delete buf; |
|
549 } |
|
550 break; |
|
551 } |
|
552 case (0x01): // ByteSeq |
|
553 { |
|
554 HBufC16* buf = NULL; |
|
555 TRAPD(headerErr, buf = HBufC16::NewL((header->AsByteSeq()).Size())); |
|
556 if (headerErr) |
|
557 { |
|
558 iParent->iConsole->Printf(_L("ByteSeq Header (0x%x)- Error allocating memory to display\r\n"), header->HI()); |
|
559 } |
|
560 else |
|
561 { |
|
562 TPtr16 type(buf->Des()); |
|
563 type.Copy(header->AsByteSeq()); |
|
564 |
|
565 iParent->iConsole->Printf(_L("ByteSeq Header (0x%x) = : \"%S\"\r\n"), header->HI(), &type); |
|
566 delete buf; |
|
567 } |
|
568 break; |
|
569 } |
|
570 case (0x02): // Byte |
|
571 { |
|
572 iParent->iConsole->Printf(_L("Byte Header (0x%x) = : 0x%x\r\n"), header->HI(), header->AsByte()); |
|
573 break; |
|
574 } |
|
575 case (0x03): //FourByte |
|
576 { |
|
577 iParent->iConsole->Printf(_L("FourByte Header (0x%x) = : 0x%x\r\n"), header->HI(), header->AsFourByte()); |
|
578 break; |
|
579 } |
|
580 default : {break;} |
|
581 } |
|
582 |
|
583 err = iObject->HeaderSet().Next(); |
|
584 } |
|
585 |
|
586 delete header; |
|
587 } |
|
588 |
|
589 TDateTime dt = iObject->Time().DateTime(); |
|
590 iParent->Console()->Printf(_L("\r\nTimestamp: %d/%d/%d, %d:%d:%d\r\n\r\n"), |
|
591 dt.Day()+1, dt.Month()+1, dt.Year(), dt.Hour(), dt.Minute(), dt.Second()); |
|
592 |
|
593 // Reset err to no error; |
|
594 err = KErrNone; |
|
595 |
|
596 if ((iObject->Name() == KRef1Name) || |
|
597 (iObject->Name() == KRef2Name) || |
|
598 (iObject->Name() == KRef3Name) || |
|
599 (iObject->Name() == KRef4Name) || |
|
600 (iObject->Name() == KRef5Name) || |
|
601 (iObject->Name() == KRef6Name) || |
|
602 (iObject->Name() == KRef7Name) || |
|
603 (iObject->Name() == KRef8Name) || |
|
604 (iObject->Name() == KRef9Name)) |
|
605 { |
|
606 iParent->Console()->Printf(_L("\r\nReference Object Received")); |
|
607 TInt objComp = 0; |
|
608 TRAP(err, objComp = iParent->iRefHandler->CompareObjectToReferenceL(*iObject, *iBuf, iParent->iTransport)); |
|
609 if ((objComp != 0) || (err != KErrNone)) // Make sure the objects match |
|
610 { |
|
611 User::Panic(_L("TOBEX - OBJCOMP"), err); |
|
612 } |
|
613 iParent->Console()->Printf(_L("\r\nReference Object Comparison OK\r\n\r\n")); |
|
614 } |
|
615 else |
|
616 { |
|
617 iParent->Console()->Printf(_L("Size of received object = %d\n"),iBuf->Size()); |
|
618 |
|
619 // Only output packet contents info if performance logging is disabled. |
|
620 if(!iParent->iPerformanceLoggingEnabled) |
|
621 { |
|
622 TBuf8<1024> tempBuffer; |
|
623 iBuf->Read(0, tempBuffer, tempBuffer.MaxSize() < iBuf->Size() ? tempBuffer.MaxSize() : iBuf->Size()); |
|
624 |
|
625 // Printf fails with Descriptor beigger than X hundred bytes so write byte at a time |
|
626 for(TInt count = 0; count < tempBuffer.Size(); count++) |
|
627 { |
|
628 iParent->Console()->Printf(_L("%C"),tempBuffer[count]); |
|
629 } |
|
630 } |
|
631 |
|
632 if (iObject->Name() != KNullDesC ) |
|
633 { |
|
634 TFileName filename; |
|
635 filename = iParent->iInboxRoot; |
|
636 |
|
637 TInt bufSpaceLeft = filename.MaxLength() - filename.Length(); |
|
638 TInt objNameLen = iObject->Name().Length(); |
|
639 TInt numToCopy = objNameLen; |
|
640 if (bufSpaceLeft < objNameLen) |
|
641 { |
|
642 numToCopy = bufSpaceLeft; |
|
643 iParent->Console()->Printf(_L("Truncated resulting local filename\n")); |
|
644 } |
|
645 filename.Append(iObject->Name().Ptr(), numToCopy); |
|
646 |
|
647 err = iObject->WriteToFile(filename); |
|
648 |
|
649 if (err == KErrAlreadyExists) |
|
650 { |
|
651 iParent->Console()->Printf(_L("\r\nWrite failed, File Already Exists\n")); |
|
652 } |
|
653 else if (err != KErrNone) |
|
654 { |
|
655 iParent->Console()->Printf(_L("\r\nWrite failed with error %d\n"), err); |
|
656 } |
|
657 } |
|
658 else |
|
659 { |
|
660 err = KErrNone; |
|
661 iParent->Console()->Printf(_L("\r\nReceived object with empty Name Header.\nNot writing to a file\n")); |
|
662 } |
|
663 } |
|
664 |
|
665 TObexHeaderMask headers = iObject->ValidHeaders(); |
|
666 iParent->Console()->Printf(_L("\n")); |
|
667 if (headers & KObexHdrBody) |
|
668 iParent->Console()->Printf(_L("Body header received\n")); |
|
669 if (headers & KObexHdrEndOfBody) |
|
670 iParent->Console()->Printf(_L("EndOfBody header received\n")); |
|
671 |
|
672 iObject->Reset (); |
|
673 #ifdef ASYNC_INDICATION |
|
674 if(err) |
|
675 { |
|
676 iServerAsyncAO->CompletionIndication(CObex::EOpPut, ERespNotAcceptable); |
|
677 } |
|
678 else |
|
679 { |
|
680 iServerAsyncAO->CompletionIndication(CObex::EOpPut, ERespSuccess); |
|
681 } |
|
682 |
|
683 #else |
|
684 return err; |
|
685 #endif |
|
686 } |
|
687 |
|
688 void CObexServerHandlerBase::HandleGetReferenceObjL(CObexBaseObject* aRequiredObject) |
|
689 { |
|
690 CObexBufObject& obj = *static_cast<CObexBufObject*>(aRequiredObject); |
|
691 CBufFlat* dummyBufPtr = CBufFlat::NewL(0); |
|
692 CleanupStack::PushL(dummyBufPtr); |
|
693 |
|
694 // See if what we got in the Get request is the same as the reference object... |
|
695 TInt objComp = iParent->iRefHandler->CompareObjectToReferenceL(obj, *dummyBufPtr, iParent->iTransport); |
|
696 CleanupStack::PopAndDestroy(dummyBufPtr); |
|
697 ASSERT(objComp == CReferenceHandler::EDifferentBuf); |
|
698 |
|
699 // Everythings OK so set up the reference object to be returned |
|
700 iParent->Console()->Printf(_L("Obex Get Reference Object Request\r\n")); |
|
701 |
|
702 |
|
703 if (aRequiredObject->Name() == KRef1Name) |
|
704 iParent->iRefHandler->CreateReferenceL(*iObject, *iBuf, 1, iParent->iTransport); |
|
705 else if (aRequiredObject->Name() == KRef2Name) |
|
706 iParent->iRefHandler->CreateReferenceL(*iObject, *iBuf, 2, iParent->iTransport); |
|
707 else if (aRequiredObject->Name() == KRef3Name) |
|
708 iParent->iRefHandler->CreateReferenceL(*iObject, *iBuf, 3, iParent->iTransport); |
|
709 else if (aRequiredObject->Name() == KRef4Name) |
|
710 iParent->iRefHandler->CreateReferenceL(*iObject, *iBuf, 4, iParent->iTransport); |
|
711 else if (aRequiredObject->Name() == KRef5Name) |
|
712 iParent->iRefHandler->CreateReferenceL(*iObject, *iBuf, 5, iParent->iTransport); |
|
713 else if (aRequiredObject->Name() == KRef6Name) |
|
714 iParent->iRefHandler->CreateReferenceL(*iObject, *iBuf, 6, iParent->iTransport); |
|
715 else if (aRequiredObject->Name() == KRef7Name) |
|
716 iParent->iRefHandler->CreateReferenceL(*iObject, *iBuf, 7, iParent->iTransport); |
|
717 else if (aRequiredObject->Name() == KRef8Name) |
|
718 iParent->iRefHandler->CreateReferenceL(*iObject, *iBuf, 8, iParent->iTransport); |
|
719 else if (aRequiredObject->Name() == KRef9Name) |
|
720 iParent->iRefHandler->CreateReferenceL(*iObject, *iBuf, 9, iParent->iTransport); |
|
721 else // capture error condition (use reference 1) |
|
722 iParent->iRefHandler->CreateReferenceL(*iObject, *iBuf, 1, iParent->iTransport); |
|
723 |
|
724 } |
|
725 |
|
726 #ifdef ASYNC_INDICATION |
|
727 void CObexServerHandlerBase::GetRequestIndication (CObexBaseObject* aRequiredObject) |
|
728 #else |
|
729 CObexBufObject* CObexServerHandlerBase::GetRequestIndication (CObexBaseObject* aRequiredObject) |
|
730 #endif |
|
731 { |
|
732 //check if app params header sent across |
|
733 if ( aRequiredObject->ValidHeaders() & KObexHdrAppParam ) |
|
734 { |
|
735 TBuf<30> localBuf; |
|
736 localBuf.Copy(aRequiredObject->AppParam()); |
|
737 |
|
738 iParent->iConsole->Printf(_L(" App Param received = : %S\r\n"), &localBuf); |
|
739 } |
|
740 else |
|
741 { |
|
742 iParent->iConsole->Printf(_L(" No App Param Headers received\r\n")); |
|
743 } |
|
744 |
|
745 //check if any HTTP headers were sent across |
|
746 if ( aRequiredObject->ValidHeaders() & KObexHdrHttp) |
|
747 { |
|
748 //OK so lets get them out |
|
749 const RPointerArray<HBufC8>* localHttpArray = aRequiredObject->Http(); |
|
750 //how many? |
|
751 TInt count = localHttpArray->Count(); |
|
752 HBufC8* localArray; |
|
753 TBuf8<30> localBuf; |
|
754 TBuf<40> buf; |
|
755 TInt size = 30; |
|
756 for ( TInt x = 0; x < count; x++ ) |
|
757 { |
|
758 localArray = (*localHttpArray)[x]; |
|
759 size = Max(localArray->Size(), 30); |
|
760 localBuf.Copy(localArray->Ptr(), size); |
|
761 buf.Copy(localBuf); |
|
762 iParent->iConsole->Printf(_L(" HTTP Header Received : %S\r\n"), &buf); |
|
763 } |
|
764 } |
|
765 else |
|
766 { |
|
767 iParent->iConsole->Printf(_L(" No HTTP Headers received\r\n")); |
|
768 } |
|
769 |
|
770 if ((aRequiredObject->Name() == KRef1Name) || |
|
771 (aRequiredObject->Name() == KRef2Name) || |
|
772 (aRequiredObject->Name() == KRef3Name) || |
|
773 (aRequiredObject->Name() == KRef4Name) || |
|
774 (aRequiredObject->Name() == KRef5Name) || |
|
775 (aRequiredObject->Name() == KRef6Name) || |
|
776 (aRequiredObject->Name() == KRef7Name) || |
|
777 (aRequiredObject->Name() == KRef8Name) || |
|
778 (aRequiredObject->Name() == KRef9Name)) |
|
779 { |
|
780 #ifdef _DEBUG |
|
781 TRAPD(err, HandleGetReferenceObjL(aRequiredObject)); |
|
782 ASSERT(err==0); |
|
783 #else |
|
784 TRAP_IGNORE(HandleGetReferenceObjL(aRequiredObject)); |
|
785 #endif |
|
786 } |
|
787 else |
|
788 { |
|
789 TRAPD(err,SetUpGetObjectL(aRequiredObject)); |
|
790 if (err != KErrNone) |
|
791 { |
|
792 iParent->Console()->Printf(_L("\nSetUpGetObjectL() returned %d.\n"), err); |
|
793 #ifdef ASYNC_INDICATION |
|
794 iServerAsyncAO->RequestIndication(CObex::EOpGet, NULL); |
|
795 #else |
|
796 iServer->RequestIndicationCallbackWithError(err); //added to test PDEF097129 |
|
797 return (NULL); |
|
798 #endif |
|
799 } |
|
800 } |
|
801 #ifdef ASYNC_INDICATION |
|
802 iServerAsyncAO->RequestIndication(CObex::EOpGet, iObject); |
|
803 #else |
|
804 return (iObject); |
|
805 #endif |
|
806 } |
|
807 |
|
808 TInt CObexServerHandlerBase::GetPacketIndication () |
|
809 { |
|
810 if (iObject->Length () > 0) |
|
811 { |
|
812 TInt percentComplete = 100 * iObject->BytesSent () / iObject->Length (); |
|
813 iParent->Console()->Printf(_L("\r%d %% "), percentComplete); |
|
814 } |
|
815 else |
|
816 { |
|
817 iParent->Console()->Printf(_L("\r%d Bytes "), iObject->BytesSent ()); |
|
818 } |
|
819 |
|
820 return (KErrNone); |
|
821 } |
|
822 |
|
823 #ifdef ASYNC_INDICATION |
|
824 void CObexServerHandlerBase::GetCompleteIndication () |
|
825 #else |
|
826 TInt CObexServerHandlerBase::GetCompleteIndication () |
|
827 #endif |
|
828 { |
|
829 iParent->Console()->Printf(_L("Obex Get Complete\r\n")); |
|
830 iObject->Reset (); |
|
831 #ifdef ASYNC_INDICATION |
|
832 iServerAsyncAO->CompletionIndication(CObex::EOpGet, ERespSuccess); |
|
833 #else |
|
834 return KErrNone; |
|
835 #endif |
|
836 } |
|
837 |
|
838 #ifdef ASYNC_INDICATION |
|
839 void CObexServerHandlerBase::SetPathIndication (const CObex::TSetPathInfo& aPathInfo, const TDesC8& /*aInfo*/) |
|
840 #else |
|
841 TInt CObexServerHandlerBase::SetPathIndication (const CObex::TSetPathInfo& aPathInfo, const TDesC8& /*aInfo*/) |
|
842 #endif |
|
843 { |
|
844 iParent->Console()->Printf(_L("Obex SetPath request:\r\n")); |
|
845 iParent->Console()->Printf(_L(" --- Flags = '%d' - Constants = '%d' - "), aPathInfo.iFlags, aPathInfo.iConstants); |
|
846 if (aPathInfo.iNamePresent) |
|
847 iParent->Console()->Printf(_L("Name = %S\r\n"), &aPathInfo.iName); |
|
848 else |
|
849 iParent->Console()->Printf(_L("> No Name Present <\r\n")); |
|
850 |
|
851 iParent->Console()->Printf(_L("\nReturning success...!\n")); |
|
852 #ifdef ASYNC_INDICATION |
|
853 iServerAsyncAO->CompletionIndication(CObex::EOpSetPath, ERespSuccess); |
|
854 #else |
|
855 return (KErrNone); |
|
856 #endif |
|
857 } |
|
858 |
|
859 void CObexServerHandlerBase::AbortIndication () |
|
860 { |
|
861 iParent->Console()->Printf(_L("Obex Operation aborted\r\n")); |
|
862 if(iObject) |
|
863 { |
|
864 if(!iObject->BytesReceived()) |
|
865 return; |
|
866 iParent->Console()->Printf(_L("\r\nWe have received part of an Obex object\r\n\r\n")); |
|
867 |
|
868 iObject->Reset();//closes file handle |
|
869 } |
|
870 } |
|
871 |
|
872 void CObexServerHandlerBase::MoraoReadActivity() |
|
873 { |
|
874 iParent->Console()->Printf(_L("Obex Server: 'Read Activity' signalled\r\n")); |
|
875 } |
|
876 |
|
877 void CObexServerHandlerBase::SetUpGetObjectL(CObexBaseObject *aRequestedObject) |
|
878 { |
|
879 TFileName name; |
|
880 name = iParent->iInboxRoot; |
|
881 name.Append(aRequestedObject->Name ()); |
|
882 if(name.Length()) |
|
883 { |
|
884 iParent->Console()->Printf(_L("Obex Get Request for name '%s'\r\n"), name.PtrZ ()); |
|
885 } |
|
886 else if (aRequestedObject->Type().Length()) |
|
887 { |
|
888 name = iParent->iInboxRoot; |
|
889 TBuf<32> temp; |
|
890 temp.Copy(aRequestedObject->Type()); |
|
891 name.Append(temp); |
|
892 iParent->Console()->Printf(_L("Obex Get Request for type '%s'\r\n"), name.PtrZ ()); |
|
893 TInt pos; |
|
894 while((pos=name.Locate('/')) >= 0) |
|
895 name[pos] = '_'; |
|
896 pos=name.Length()-1; |
|
897 if(pos>=0 && name[pos] == 0) |
|
898 name.SetLength(pos); // Work around last character possibly being NULL |
|
899 } |
|
900 else |
|
901 { |
|
902 iParent->Console()->Printf(_L("Obex Get Request unknown details\r\n")); |
|
903 User::Leave(KErrNotSupported); |
|
904 } |
|
905 iObject->Reset(); |
|
906 |
|
907 RFs fs; |
|
908 RFile f; |
|
909 if ((fs.Connect () != KErrNone) || |
|
910 (f.Open (fs, name, EFileShareReadersOnly | EFileRead) != KErrNone)) |
|
911 { |
|
912 iParent->Console()->Printf(_L("\r\nError reading '%S'."), &name); |
|
913 User::Leave(KErrNotFound); |
|
914 } |
|
915 |
|
916 TInt size = 0; |
|
917 User::LeaveIfError(f.Size (size)); |
|
918 iBuf->ResizeL(size); |
|
919 TPtr8 data (iBuf->Ptr(0)); |
|
920 f.Read (data); |
|
921 if (iBuf->Size() < size) |
|
922 User::Leave(KErrGeneral); |
|
923 iObject->SetNameL(name); |
|
924 iObject->SetLengthL(size); |
|
925 TTime time; |
|
926 if (f.Modified(time) == KErrNone) |
|
927 iObject->SetTimeL(time); |
|
928 } |
|
929 |
|
930 void CObexServerHandlerBase::EnableAuthentication() |
|
931 { |
|
932 TRAPD(err, iServer->SetChallengeL(iChallengePassword)); |
|
933 if (err == KErrNone) |
|
934 { |
|
935 iIsAuthenticationEnabled = ETrue; |
|
936 } |
|
937 else |
|
938 { |
|
939 iParent->iConsole->Printf(_L("Failed to set authentication password\r\n")); |
|
940 } |
|
941 } |
|
942 |
|
943 void CObexServerHandlerBase::DisableAuthentication() |
|
944 { |
|
945 iServer->ResetChallenge(); |
|
946 iIsAuthenticationEnabled = EFalse; |
|
947 } |
|
948 |
|
949 void CObexServerHandlerBase::EnablePassword() |
|
950 { |
|
951 iServer->SetCallBack(*this); |
|
952 } |
|
953 |
|
954 void CObexServerHandlerBase::ChangeChallengePassword(TDesC* aPassword) |
|
955 { |
|
956 if (aPassword) |
|
957 iChallengePassword = *aPassword; |
|
958 else |
|
959 iParent->SetPassword(iChallengePassword); |
|
960 |
|
961 if (iIsAuthenticationEnabled) |
|
962 { |
|
963 DisableAuthentication(); |
|
964 EnableAuthentication(); |
|
965 } |
|
966 } |
|
967 |
|
968 void CObexServerHandlerBase::ChangeResponsePassword() |
|
969 { |
|
970 iParent->Cancel(); |
|
971 iParent->SetPassword(iResponsePassword); |
|
972 iParent->RequestCharacter(); // re-request, to re-display menu |
|
973 } |
|
974 |
|
975 void CObexServerHandlerBase::GetUserPasswordL(const TDesC& aUserID) |
|
976 { |
|
977 iParent->Console()->Printf(_L("\r\nServer has been challenged by %S"), &aUserID); |
|
978 ChangeResponsePassword(); //get the password from user |
|
979 iServer->UserPasswordL(iResponsePassword); |
|
980 } |
|
981 |
|
982 void CObexServerHandlerBase::SetLocalWho() |
|
983 { |
|
984 iServer->SetLocalWho(KRefTarget); |
|
985 } |
|
986 |
|
987 #ifdef ASYNC_INDICATION |
|
988 void CObexServerHandlerBase::CancelIndicationCallback() |
|
989 { |
|
990 iServerAsyncAO->Cancel(); |
|
991 } |
|
992 #endif |
|
993 |
|
994 #ifdef PACKET_ACCESS_EXTENSION |
|
995 void CObexServerHandlerBase::PacketAccessUiL(TBool aEnable) |
|
996 { |
|
997 if (aEnable) |
|
998 { |
|
999 iPacketAccessUi = CObexServerPacketAccessUi::NewL(*this, *iServer); |
|
1000 } |
|
1001 else |
|
1002 { |
|
1003 delete iPacketAccessUi; |
|
1004 iPacketAccessUi = NULL; |
|
1005 } |
|
1006 } |
|
1007 #endif // PACKET_ACCESS_EXTENSION |