|
1 // Copyright (c) 1997-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 // obex_client.cpp [stub] |
|
15 // oscarg, September 2003. |
|
16 // This is a modified version of Obex.cpp. |
|
17 // Modified file for BT/IR OBEX stub |
|
18 // |
|
19 // |
|
20 |
|
21 #include <charconv.h> |
|
22 //#include "debug.h" |
|
23 #include "trans.h" |
|
24 #include "obex.h" |
|
25 #include "obexutil.h" |
|
26 //#include "authentication.h" |
|
27 |
|
28 |
|
29 // |
|
30 // class CObex |
|
31 // |
|
32 |
|
33 CObex::CObex() |
|
34 { |
|
35 SetConnectState(EConnIdle); |
|
36 iConnector = NULL; |
|
37 iTransport = NULL; |
|
38 iCallBack = NULL; |
|
39 iChallPassword = NULL; |
|
40 iRespPassword = NULL; |
|
41 iRxChallenge = NULL; |
|
42 iCallBack = NULL; |
|
43 iChallenge = EFalse; |
|
44 iRemoteRealm = NULL; |
|
45 iRemoteUID = NULL; |
|
46 } |
|
47 |
|
48 void CObex::ConstructL(TObexProtocolInfo& /*aObexProtocolInfoPtr*/) |
|
49 { |
|
50 } |
|
51 |
|
52 |
|
53 |
|
54 CObex::~CObex() |
|
55 { |
|
56 DeleteTransport(); |
|
57 DeleteConnector(); |
|
58 iSocketServ.Close(); |
|
59 //delete iAuthEngine; |
|
60 delete iChallPassword; |
|
61 delete iRespPassword; |
|
62 delete iRemoteUID; |
|
63 delete iRemoteRealm; |
|
64 delete iRxChallenge; |
|
65 |
|
66 } |
|
67 |
|
68 EXPORT_C void CObex::RemoteAddr(TSockAddr& /*aAddr*/) |
|
69 { |
|
70 } |
|
71 |
|
72 EXPORT_C TInt CObex::SetLocalWho(const TDesC8& aInfo) |
|
73 /** |
|
74 The local who field is used to identify the local end of the OBEX session |
|
75 when the OBEX connection is made. Set this to a unique value before |
|
76 establishing the connection, if recognition strict peers (i.e. a peer also |
|
77 using this who value) is required. |
|
78 **/ |
|
79 { |
|
80 if(aInfo.Length()) |
|
81 { iLocalInfo.iWho.Copy(aInfo); return KErrNone;} |
|
82 else |
|
83 return KErrArgument; |
|
84 } |
|
85 |
|
86 void CObex::PrepareChallResponseL(const TDesC& /*aPassword*/) |
|
87 { |
|
88 } |
|
89 |
|
90 |
|
91 |
|
92 TInt CObex::GenerateChallenge(TObexPacket& /*aPacket*/) |
|
93 { |
|
94 return KErrNone; |
|
95 } |
|
96 |
|
97 void CObex::ProcessChallResponseL(const TObexInternalHeader& /*hdr*/) |
|
98 { |
|
99 } |
|
100 |
|
101 void CObex::ProcessChallengeL(const TObexInternalHeader& /*hdr*/) |
|
102 { |
|
103 } |
|
104 |
|
105 EXPORT_C void CObex::SetCallBack(MObexAuthChallengeHandler& aCallBack) |
|
106 { |
|
107 iCallBack = &aCallBack; |
|
108 } |
|
109 |
|
110 void CObex::Process(TObexPacket& /*aPacket*/) |
|
111 { |
|
112 } |
|
113 |
|
114 void CObex::Error(TInt aError) |
|
115 { |
|
116 OnError(aError); |
|
117 } |
|
118 |
|
119 void CObex::TransportUp(TObexConnectionInfo& /*aInfo*/) |
|
120 { |
|
121 } |
|
122 |
|
123 void CObex::TransportDown(TBool /*aForceTransportDeletion*/) |
|
124 { |
|
125 } |
|
126 |
|
127 void CObex::BringTransportDown() |
|
128 { |
|
129 } |
|
130 |
|
131 void CObex::NewConnectorL(TObexProtocolInfo& /*aObexProtocolInfoPtr*/) |
|
132 { |
|
133 } |
|
134 |
|
135 void CObex::DeleteConnector() |
|
136 { |
|
137 delete iConnector; |
|
138 iConnector = NULL; |
|
139 } |
|
140 |
|
141 void CObex::NewTransportL(TObexConnectionInfo& /*aInfo*/) |
|
142 { |
|
143 } |
|
144 |
|
145 void CObex::DeleteTransport() |
|
146 { |
|
147 delete iTransport; |
|
148 iTransport = NULL; |
|
149 } |
|
150 |
|
151 void CObex::SetConnectState(TConnectState aNewState) |
|
152 { |
|
153 iConnectState = aNewState; |
|
154 } |
|
155 |
|
156 // CObex::TSetPathInfo |
|
157 EXPORT_C CObex::TSetPathInfo::TSetPathInfo() |
|
158 /** |
|
159 @publishedAll |
|
160 @released |
|
161 */ |
|
162 { |
|
163 iFlags = 0; |
|
164 iConstants = 0; |
|
165 iNamePresent = EFalse; |
|
166 } |
|
167 |
|
168 EXPORT_C TBool CObex::TSetPathInfo::Parent() const |
|
169 /** |
|
170 @publishedAll |
|
171 @released |
|
172 */ |
|
173 { |
|
174 return(iFlags & KObexSetPathParent); |
|
175 } |
|
176 |
|
177 // CObex |
|
178 EXPORT_C TBool CObex::IsConnected() const |
|
179 /** |
|
180 Returns @c ETrue if this CObex is connected at an OBEX level, merely having |
|
181 a transport connected does not satisfy this condition. I.e. the two devices |
|
182 must have completed the OBEX connection request/response . All other states |
|
183 return @c EFalse. This will be unreliable if either the server blindly |
|
184 returns the client’s who header (always reporting ETrue), or if neither |
|
185 supply "who" headers (always reporting EFalse). |
|
186 |
|
187 @publishedAll |
|
188 @released |
|
189 **/ |
|
190 { |
|
191 return(ConnectState() == EConnObex); |
|
192 } |
|
193 |
|
194 EXPORT_C TBool CObex::IsStrictPeer() const |
|
195 /** |
|
196 Returns true if the "who" header specified in the server’s connect response |
|
197 matched that of the client’s connect request, and both had a length greater |
|
198 than 0 (i.e. both specified a "who" field). Undefined if @c IsConnected() |
|
199 == @c EFalse. |
|
200 |
|
201 @publishedAll |
|
202 @released |
|
203 **/ |
|
204 { |
|
205 return((iLocalInfo.iWho.Length()>0) && (iLocalInfo.iWho==iRemoteInfo.iWho)); |
|
206 } |
|
207 |
|
208 EXPORT_C const TObexConnectInfo& CObex::LocalInfo() const |
|
209 /** |
|
210 Use this member to gain access to (and alter, if necessary) the |
|
211 CObex::TConnectInfo structure which will be sent to the OBEX peer as part |
|
212 of the connection process. Only alter the contents of this having read and |
|
213 understood the purpose of the fields, as defined in the OBEX spec. Altering |
|
214 this structure after a connection has been made will have no effect on the |
|
215 current session, but will be used for future connection attempts. |
|
216 |
|
217 @publishedAll |
|
218 @released |
|
219 **/ |
|
220 { |
|
221 return(iLocalInfo); |
|
222 } |
|
223 |
|
224 |
|
225 EXPORT_C const TObexConnectInfo& CObex::RemoteInfo() const |
|
226 /** |
|
227 Use this member to read the details of the remote machine’s connection |
|
228 information, as specified by it in during OBEX connection. This data can |
|
229 not be altered, as this serves no purpose. |
|
230 The content of this structure is undefined when @c IsConnected () == @c |
|
231 EFalse. |
|
232 |
|
233 @publishedAll |
|
234 @released |
|
235 **/ |
|
236 { |
|
237 return(iRemoteInfo); |
|
238 } |
|
239 |
|
240 EXPORT_C CObex::TConnectState CObex::ConnectState() const |
|
241 { |
|
242 return (iConnectState); |
|
243 }; |
|
244 |
|
245 |
|
246 /** |
|
247 @ fn virtual void MObexServerNotify::ErrorIndication (TInt aError) =0; |
|
248 This function will be called when some form of OBEX protocol error occurs, the |
|
249 passed parameter aError is a standard EPOC error code which describes the |
|
250 nature of this error. It is only be called for fatal errors, in that the OBEX |
|
251 connection will be brought down and then the error indication passed. Any |
|
252 error which does not bring the connection down will not be indicated, for |
|
253 example the server issuing a semantically valid, but unrecognised command. |
|
254 |
|
255 @publishedAll |
|
256 @released |
|
257 **/ |
|
258 |
|
259 /** @fn virtual void MObexServerNotify::TransportUpIndication () =0; |
|
260 Called when the underlying socket transport connection is made from a remote |
|
261 client to the server. Note that this does not, however, indicate an OBEX |
|
262 connection has been successfully established. Define any low-level connection |
|
263 policy here. Also a good place to set up the LocalConnectInfo, if any |
|
264 non-defaults are required. |
|
265 |
|
266 @publishedAll |
|
267 @released |
|
268 **/ |
|
269 |
|
270 /** @fn virtual void MObexServerNotify::TransportDownIndication () =0; |
|
271 Override this to provide processing when the transport connection is dropped |
|
272 (by either party), whether the OBEX connection was gracefully disconnected or |
|
273 not. This is the definitive place for disconnection processing; it will always |
|
274 be called on disconnection. |
|
275 |
|
276 @publishedAll |
|
277 @released |
|
278 **/ |
|
279 |
|
280 /** @fn virtual TInt MObexServerNotify::ObexConnectIndication (const CObex::TConnectInfo& aRemoteInfo, const TDesC8& aInfo) =0; |
|
281 Override this function to provide extra processing when an OBEX connection is |
|
282 made from a remote client. |
|
283 @param aRemoteInfo holds the connection information supplied by that |
|
284 remote machine. |
|
285 @param aInfo holds further information about the requested |
|
286 connection (reserved). |
|
287 @return EPOC error indicating the success of the connection. |
|
288 |
|
289 @publishedAll |
|
290 @released |
|
291 **/ |
|
292 |
|
293 /** fn virtual void MObexServerNotify::ObexDisconnectIndication (const TDesC8& aInfo) =0; |
|
294 Override this to provide extra processing on a (graceful) OBEX disconnection |
|
295 by the client. |
|
296 @param aInfo Contains information about the disconnection (reserved). |
|
297 @note This indication will not be raised if the remote machine simply |
|
298 drops the transport connection. However, ErrorIndication () will be called if |
|
299 the disconnection is unexpected/ invalid (i.e. another operation was in |
|
300 progress at the time). In all cases, TransportDownIndication () will be |
|
301 called. |
|
302 |
|
303 @publishedAll |
|
304 @released |
|
305 **/ |
|
306 |
|
307 /** @fn virtual CObexBaseObject* MObexServerNotify::PutRequestIndication () =0; |
|
308 Called on receipt of the first packet of a (valid) put request. It is called |
|
309 before any parsing of the packet is performed, simply to establish whether |
|
310 this server is interested in receiving objects at all. |
|
311 @return a pointer to a CObexBaseObject derived object, which the object |
|
312 being put will be parsed into. |
|
313 @return NULL ERespForbidden will be returned to the client. |
|
314 @note If the returned object cannot be initialised for receiving (e.g. a |
|
315 tempory file could not be created for CObexFileObjects) |
|
316 ERespInternalError will be returned to the client. |
|
317 |
|
318 @publishedAll |
|
319 @released |
|
320 **/ |
|
321 |
|
322 /** @fn virtual TInt MObexServerNotify::PutPacketIndication () =0; |
|
323 Called on receipt of every packet of an OBEX ‘put’ operation. It will always |
|
324 be preceded by a PutRequestIndicatoin(). The object returned by the request |
|
325 indication will updated to reflect all the information received concerning the |
|
326 object which the client is sending, from packets up to and including the |
|
327 current one. |
|
328 @return KErrNone instructs the server to allow the client to continue the |
|
329 put operation. |
|
330 @return - any other value the operation is cancelled with an |
|
331 appropriate OBEX server response code. |
|
332 Use this function to provide periodic user notification on the progress of the |
|
333 transfer (noting that the Length attribute may take an arbitrary number of |
|
334 packets to become non-zero, and the constraints on its accuracy). Due to the |
|
335 nature of OBEX operations, where any header attribute can be sent at any point |
|
336 in the transfer, this is also a good place to marshal the details of a |
|
337 received object, and possibly prompt for action on the received object (e.g. |
|
338 renaming on filename clashes). |
|
339 @note It is worth noting that this function could be hit quite heavily, in |
|
340 proportion to the size of the object transferred. Therefore more consideration |
|
341 should be given to the speed of execution of this function than that of the |
|
342 other indications. |
|
343 |
|
344 @publishedAll |
|
345 @released |
|
346 **/ |
|
347 |
|
348 /** @fn virtual TInt MObexServerNotify::PutCompleteIndication () =0; |
|
349 Called after the final put packet has been successfully received and parsed. |
|
350 @return KErrNone instructs the remote client that the put completed successfully. |
|
351 @return - any other value the operation is cancelled with an |
|
352 appropriate OBEX server response code. |
|
353 @note Note that there will not necessarily be a call to this function |
|
354 corresponding to each PutRequestIndication; if an error occurs while the put |
|
355 is being carried out ErrorIndication will be called instead. |
|
356 @since 6.1 Before 6.1, the return type was void. |
|
357 |
|
358 @publishedAll |
|
359 @released |
|
360 **/ |
|
361 |
|
362 /** @fn virtual CObexBaseObject* MObexServerNotify::GetRequestIndication (CObexBaseObject* aRequestedObject) =0; |
|
363 Called when a full get request has been received from the client. |
|
364 aRequestedObject holds all the details about the object the remote client has |
|
365 requested. Use this function to analyse the clients request, and return a |
|
366 pointer to the object to be returned to the client, or NULL to return no |
|
367 object. If NULL is returned, the server will send ERespForbidden to the |
|
368 client, if an error occurs in returning the object, ERespInternalError is |
|
369 returned, otherwise the returned object is sent back to the client. |
|
370 |
|
371 @publishedAll |
|
372 @released |
|
373 **/ |
|
374 |
|
375 /** @fn virtual TInt MObexServerNotify::GetPacketIndication () =0; |
|
376 Called for every packet of get reply sent by the server back to the client. |
|
377 That is, it is only called while an object is being sent to the client, not |
|
378 while the client is providing its initial specification for the object it |
|
379 requires. Return KErrNone to continue sending the object, or some other error |
|
380 code to cancel the operation. |
|
381 Use this function to provide user notification on the object being sent, and |
|
382 its progress. As with PutPacketIndication, it is worth bearing in mind that |
|
383 this packet might get called quite heavily, especially for large objects and |
|
384 small OBEX packet sizes, so the speed of execution here is important. |
|
385 |
|
386 @publishedAll |
|
387 @released |
|
388 **/ |
|
389 |
|
390 /** @fn virtual TInt MObexServerNotify::GetCompleteIndication () =0; |
|
391 Called when the final packet of the object has been returned to the client. |
|
392 @return KErrNone instructs the remote client that the get completed successfully. |
|
393 @return - any other value the operation is cancelled with an |
|
394 appropriate OBEX server response code. |
|
395 @note Like PutCompleteIndication, this function might not be |
|
396 called for each GetRequestIndication, if the operation is interrupted by an |
|
397 error. |
|
398 @since 6.1 Before 6.1, the return type was void. |
|
399 |
|
400 @publishedAll |
|
401 @released |
|
402 **/ |
|
403 |
|
404 /** @fn virtual TInt MObexServerNotify::SetPathIndication (const CObex::TSetPathInfo& aPathInfo, const TDesC8& aInfo) =0; |
|
405 Indicates a SETPATH command has been received by the server. |
|
406 @param aPathInfo Will contain the flags, constants, and |
|
407 name (if present) for this Setpath |
|
408 @param aInfo Not currently used: will be == KNullDesC |
|
409 |
|
410 @return An EPOC error code indicating the success of the setpath. |
|
411 |
|
412 |
|
413 @publishedAll |
|
414 @released |
|
415 **/ |
|
416 |
|
417 /** @fn virtual void MObexServerNotify::AbortIndication () =0; |
|
418 Called when an abort packet is received from the client. An OBEX abort command |
|
419 simply cancels the current operation, and does not necessarily have to cause |
|
420 the connection to be dropped. On return, a ERespSuccess packet is sent to the |
|
421 client. |
|
422 |
|
423 @publishedAll |
|
424 @released |
|
425 **/ |
|
426 |
|
427 /** @fn virtual void MObexAuthChallengeHandler::GetUserPasswordL(const TDesC& aRealm) =0; |
|
428 Indicates that the server/client has received an Authentication challenge. The challenge |
|
429 can only be responded to once a password has been retrieved by some means and passed |
|
430 back to the calling class. The password is passed back via |
|
431 CObex::UserPasswordL( const TDesC& aPassword) |
|
432 @param aRealm this will contain the Realm specified by the unit forcing |
|
433 the Authentication, if no UserID was supplied then this |
|
434 parameter will be of zero length. |
|
435 |
|
436 @publishedAll |
|
437 @released |
|
438 **/ |
|
439 |
|
440 |
|
441 // |
|
442 // |
|
443 // DLL entry point |
|
444 // |
|
445 // The reason code is of no interest here and it is ignored |
|
446 // |
|
447 |
|
448 GLDEF_C TInt E32Dll(TDllReason /*aReason*/) |
|
449 { |
|
450 return KErrNone; |
|
451 } |