|
1 /* |
|
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html." |
|
8 * Initial Contributors: |
|
9 * Nokia Corporation - initial contribution. |
|
10 * Contributors: |
|
11 * |
|
12 * Description: |
|
13 * MSRP Implementation |
|
14 * |
|
15 */ |
|
16 |
|
17 // Include Files |
|
18 #include "CMSRPSessionImplementation.h" |
|
19 #include "msrpstrings.h" |
|
20 #include "MSRPStrConsts.h" |
|
21 #include "RMSRPSession.h" |
|
22 #include "MMSRPSessionObserver.h" |
|
23 #include "CMSRPConnectionListener.h" |
|
24 #include "CMSRPIncomingListener.h" |
|
25 #include "CMSRPSendResultListener.h" |
|
26 #include "CMSRPMessage.h" |
|
27 #include "CMSRPToPathHeader.h" |
|
28 #include "CMSRPFromPathHeader.h" |
|
29 #include "CMSRPMessageIdHeader.h" |
|
30 #include "CMSRPSuccessReportHeader.h" |
|
31 #include "CMsrpFailureReportHeader.h" |
|
32 #include "CMsrpContentTypeHeader.h" |
|
33 #include "CMSRPSessionParams.h" |
|
34 |
|
35 |
|
36 // SYSTEM INCLUDES |
|
37 #include <e32math.h> |
|
38 |
|
39 |
|
40 // Constants |
|
41 const TInt KMsrpFixedLength=19; // fixed length of a uri |
|
42 |
|
43 |
|
44 // Member Functions |
|
45 |
|
46 CMSRPSessionImplementation* CMSRPSessionImplementation::NewL( RMSRP& aRMSRP, |
|
47 MMSRPSessionObserver& aObserver, |
|
48 const TUint aIapId ) |
|
49 { |
|
50 MSRPLOG("CMSRPSessionImplementation::NewL"); |
|
51 CMSRPSessionImplementation *self = CMSRPSessionImplementation::NewLC( aRMSRP, aObserver, aIapId ); |
|
52 |
|
53 CleanupStack::Pop(self); |
|
54 return self; |
|
55 } |
|
56 |
|
57 |
|
58 CMSRPSessionImplementation* CMSRPSessionImplementation::NewLC( RMSRP& aRMSRP, |
|
59 MMSRPSessionObserver& aObserver, |
|
60 const TUint aIapId ) |
|
61 { |
|
62 MSRPLOG("CMSRPSessionImplementation::NewLC"); |
|
63 CMSRPSessionImplementation *self = new (ELeave) CMSRPSessionImplementation( aRMSRP, aObserver ); |
|
64 |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL( aIapId ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 CMSRPSessionImplementation::CMSRPSessionImplementation( RMSRP& aRMSRP, |
|
71 MMSRPSessionObserver& aObserver ) |
|
72 :iRMSRP(aRMSRP), |
|
73 iSessionObserver(aObserver), |
|
74 iSuccessReport(ENo), |
|
75 iFailureReport(EYes) |
|
76 { |
|
77 MSRPLOG("CMSRPSessionImplementation::Ctor"); |
|
78 } |
|
79 |
|
80 |
|
81 void CMSRPSessionImplementation::ConstructL( const TUint aIapId ) |
|
82 { |
|
83 MSRPLOG("CMSRPSessionImplementation::ConstructL enter"); |
|
84 |
|
85 MSRPStrings::OpenL(); |
|
86 iMSRPSession = new ( ELeave ) RMSRPSession(); |
|
87 |
|
88 User::LeaveIfError(iMSRPSession->CreateServerSubSession( iRMSRP, aIapId ) ); |
|
89 MSRPLOG("Sub session opened successfully!"); |
|
90 |
|
91 RBuf8 sessionID; |
|
92 sessionID.CreateL( KMaxLengthOfSessionId ); |
|
93 CleanupClosePushL( sessionID ); |
|
94 |
|
95 RBuf8 localHost; |
|
96 localHost.CreateL( KMaxLengthOfHost ); |
|
97 CleanupClosePushL( localHost ); |
|
98 |
|
99 iMSRPSession->GetLocalPathL( localHost, sessionID ); |
|
100 |
|
101 iLocalMsrpPath.CreateL( KMsrpUriScheme, KMsrpFixedLength + localHost.Length() + sessionID.Length() ); |
|
102 |
|
103 iLocalMsrpPath.Append( localHost ); |
|
104 iLocalMsrpPath.Append( KColon ); |
|
105 iLocalMsrpPath.AppendNum( KMsrpPort ); |
|
106 iLocalMsrpPath.Append( KForwardSlash ); |
|
107 iLocalMsrpPath.Append( sessionID ); |
|
108 iLocalMsrpPath.Append( KSemicolon ); |
|
109 iLocalMsrpPath.Append( KTransport ); |
|
110 |
|
111 |
|
112 iConnectionListener = CMSRPConnectionListener::NewL( |
|
113 *this, *iMSRPSession ); |
|
114 iIncomingListener = CMSRPIncomingListener::NewL( |
|
115 *this, *iMSRPSession ); |
|
116 iSendResultListener = CMSRPSendResultListener::NewL( |
|
117 *this, *iMSRPSession, sessionID ); |
|
118 |
|
119 CleanupStack::PopAndDestroy(2); //sessionID and localHost |
|
120 MSRPLOG("CMSRPSessionImplementation::ConstructL exit"); |
|
121 } |
|
122 |
|
123 |
|
124 CMSRPSessionImplementation::~CMSRPSessionImplementation() |
|
125 { |
|
126 MSRPLOG("CMSRPSessionImplementation::Dtor Entered"); |
|
127 |
|
128 MSRPStrings::Close(); |
|
129 iLocalMsrpPath.Close(); |
|
130 iRemoteMsrpPath.Close(); |
|
131 |
|
132 delete iConnectionListener; |
|
133 delete iIncomingListener; |
|
134 delete iSendResultListener; |
|
135 |
|
136 iSentMessages.ResetAndDestroy(); |
|
137 iSentMessages.Close(); |
|
138 |
|
139 if( iMSRPSession ) |
|
140 { |
|
141 iMSRPSession->CloseServerSubSession(); |
|
142 } |
|
143 delete iMSRPSession; |
|
144 |
|
145 MSRPLOG("CMSRPSessionImplementation::Dtor Exit"); |
|
146 } |
|
147 |
|
148 |
|
149 TDesC8& CMSRPSessionImplementation::LocalMSRPPath() |
|
150 { |
|
151 MSRPLOG("CMSRPSessionImplementation::LocalMSRPPath"); |
|
152 return iLocalMsrpPath; |
|
153 } |
|
154 |
|
155 |
|
156 void CMSRPSessionImplementation::SetSessionParams( CMSRPSessionParams& aSessionParams ) |
|
157 { |
|
158 MSRPLOG("CMSRPSessionImplementation::SetSessionParams"); |
|
159 iSuccessReport = aSessionParams.SuccessReportHeader(); |
|
160 iFailureReport = aSessionParams.FailureReportHeader(); |
|
161 } |
|
162 |
|
163 |
|
164 void CMSRPSessionImplementation::GetRemotePathComponentsL( TPtrC8& aRemoteHost, TUint& aRemotePort, TPtrC8& aRemoteSessionID ) |
|
165 { |
|
166 MSRPLOG("CMSRPSessionImplementation::GetRemotePathComponentsL enter"); |
|
167 TUriParser8 parser; |
|
168 User::LeaveIfError( parser.Parse( iRemoteMsrpPath ) ); |
|
169 |
|
170 aRemoteHost.Set( parser.Extract( EUriHost ) ); |
|
171 |
|
172 const TDesC8& remPort = parser.Extract( EUriPort ); |
|
173 |
|
174 TLex8 portLex(remPort); |
|
175 User::LeaveIfError( portLex.Val( aRemotePort ) ); |
|
176 |
|
177 const TDesC8& remotePath = parser.Extract( EUriPath ); |
|
178 |
|
179 TInt loc = remotePath.Find( KSemicolon ); |
|
180 aRemoteSessionID.Set( remotePath.Mid( 1, loc-1) ); |
|
181 MSRPLOG("CMSRPSessionImplementation::GetRemotePathComponentsL exit"); |
|
182 } |
|
183 |
|
184 |
|
185 void CMSRPSessionImplementation::ConnectL( const TDesC8& aRemoteMsrpPath ) |
|
186 { |
|
187 MSRPLOG("CMSRPSessionImplementation::ConnectL enter"); |
|
188 |
|
189 iRemoteMsrpPath.CreateL( aRemoteMsrpPath ); |
|
190 |
|
191 TPtrC8 remoteHost; |
|
192 TPtrC8 remoteSessionID; |
|
193 TUint remotePort; |
|
194 |
|
195 GetRemotePathComponentsL( remoteHost, remotePort, remoteSessionID ); |
|
196 |
|
197 iConnectionListener->ConnectL( remoteHost, remotePort, remoteSessionID ); |
|
198 MSRPLOG("CMSRPSessionImplementation::ConnectL exit"); |
|
199 } |
|
200 |
|
201 |
|
202 void CMSRPSessionImplementation::ListenL( const TDesC8& aRemoteMsrpPath ) |
|
203 { |
|
204 MSRPLOG("CMSRPSessionImplementation::ListenL enter"); |
|
205 |
|
206 iRemoteMsrpPath.CreateL( aRemoteMsrpPath ); |
|
207 |
|
208 TPtrC8 remoteHost; |
|
209 TPtrC8 remoteSessionID; |
|
210 TUint remotePort; |
|
211 |
|
212 GetRemotePathComponentsL( remoteHost, remotePort, remoteSessionID ); |
|
213 |
|
214 iIncomingListener->ListenConnections( remoteHost, remotePort, remoteSessionID ); |
|
215 MSRPLOG("CMSRPSessionImplementation::ListenL exit"); |
|
216 } |
|
217 |
|
218 |
|
219 void CMSRPSessionImplementation::ConnectionEstablishedL( TInt aStatus ) |
|
220 { |
|
221 |
|
222 MSRPLOG("CMSRPSessionImplementation::ConnectionEstablished enter"); |
|
223 |
|
224 iSessionObserver.ConnectStatus(aStatus); |
|
225 if ( aStatus == KErrNone ) |
|
226 { |
|
227 // start listening to incoming messages directed to this session |
|
228 iIncomingListener->ListenMessages( ); |
|
229 |
|
230 // start listening when message has been sent, to responses |
|
231 iSendResultListener->ListenSendResultL( ); |
|
232 } |
|
233 |
|
234 MSRPLOG("CMSRPSessionImplementation::ConnectionEstablished exit"); |
|
235 } |
|
236 |
|
237 |
|
238 void CMSRPSessionImplementation::HandleIncomingMessageL( |
|
239 const TDesC8& aIncomingMessage, TInt aStatus ) |
|
240 { |
|
241 MSRPLOG( "CMSRPSessionImplementation::HandleIncomingMessageL enter" ) |
|
242 |
|
243 // the incoming buffer must be internalized |
|
244 RDesReadStream readStream( aIncomingMessage ); |
|
245 |
|
246 if ( CMSRPMessage::IsMessage( aIncomingMessage ) ) |
|
247 { |
|
248 CMSRPMessage* message = NULL; |
|
249 message = CMSRPMessage::InternalizeL( readStream ); |
|
250 CleanupStack::PushL(message); |
|
251 |
|
252 HBufC8* messageContent = NULL; |
|
253 if(message->IsContent()) |
|
254 { |
|
255 messageContent = HBufC8::NewL(message->Content().Length()); |
|
256 CleanupStack::PushL( messageContent ); |
|
257 *messageContent = message->Content(); |
|
258 } |
|
259 else |
|
260 { |
|
261 messageContent = HBufC8::NewL(KNullDesC8().Length()); |
|
262 CleanupStack::PushL( messageContent ); |
|
263 *messageContent = KNullDesC8(); |
|
264 } |
|
265 |
|
266 iSessionObserver.IncomingMessage( messageContent, aStatus ); |
|
267 CleanupStack::Pop( messageContent ); |
|
268 CleanupStack::PopAndDestroy(message); |
|
269 } |
|
270 else |
|
271 { |
|
272 User::Leave( KErrArgument ); |
|
273 } |
|
274 |
|
275 MSRPLOG( "CMSRPSessionImplementation::HandleIncomingMessageL exit" ) |
|
276 } |
|
277 |
|
278 void CMSRPSessionImplementation::ReceiveProgress(TInt aBytesReceived, TInt aTotalBytes) |
|
279 { |
|
280 iSessionObserver.FileReceiveProgress(aBytesReceived, aTotalBytes); |
|
281 } |
|
282 |
|
283 void CMSRPSessionImplementation::SendProgress(TInt aBytesSent, TInt aTotalBytes) |
|
284 { |
|
285 iSessionObserver.FileSendProgress(aBytesSent, aTotalBytes); |
|
286 } |
|
287 |
|
288 CMSRPMessage* CMSRPSessionImplementation::CreateMsrpMessageL( |
|
289 const TDesC8& aMessage, const TDesC8& aToPath, |
|
290 const TDesC8& aFromPath, const TDesC8& aMimeType ) |
|
291 { |
|
292 |
|
293 MSRPLOG( "CMSRPSessionImplementation::CreateMsrpMessageL enter" ) |
|
294 |
|
295 // To path |
|
296 CMSRPMessage* msrpMessage = new ( ELeave ) CMSRPMessage(); |
|
297 CleanupStack::PushL( msrpMessage ); |
|
298 CMSRPToPathHeader* toPath = CMSRPToPathHeader::DecodeL( aToPath ); |
|
299 msrpMessage->SetToPathHeader( toPath ); |
|
300 |
|
301 // from path |
|
302 CMSRPFromPathHeader* fromPath = CMSRPFromPathHeader::DecodeL( aFromPath ); |
|
303 msrpMessage->SetFromPathHeader( fromPath ); |
|
304 |
|
305 // message id header |
|
306 TTime now; |
|
307 now.HomeTime(); |
|
308 TInt64 seed = now.Int64(); |
|
309 // Create a random number as the session ID |
|
310 TInt random = Math::Rand( seed ); |
|
311 TBuf8< 100 > idString; |
|
312 idString.AppendNum( random ); |
|
313 CMSRPMessageIdHeader* messageIdHeader = CMSRPMessageIdHeader::NewL( idString ); |
|
314 msrpMessage->SetMessageIdHeader( messageIdHeader ); |
|
315 |
|
316 // success report header |
|
317 if( iSuccessReport != ENo ) |
|
318 { |
|
319 RStringF string = MSRPStrings::StringF( MSRPStrConsts::EYes ); |
|
320 CMSRPSuccessReportHeader* successReportHeader = CMSRPSuccessReportHeader::NewL( string ); |
|
321 msrpMessage->SetSuccessReportHeader( successReportHeader ); |
|
322 } |
|
323 |
|
324 // failure report header |
|
325 if( iFailureReport != EYes ) |
|
326 { |
|
327 RStringF string; |
|
328 CleanupClosePushL(string); |
|
329 if( iFailureReport == ENo ) |
|
330 { |
|
331 string = MSRPStrings::StringF( MSRPStrConsts::ENo ); |
|
332 } |
|
333 else |
|
334 { |
|
335 string = MSRPStrings::StringF( MSRPStrConsts::EPartial ); |
|
336 } |
|
337 CMSRPFailureReportHeader* failureReportHeader = CMSRPFailureReportHeader::NewL( string ); |
|
338 msrpMessage->SetFailureReportHeader( failureReportHeader ); |
|
339 CleanupStack::PopAndDestroy(); // string |
|
340 } |
|
341 |
|
342 // content type |
|
343 if(aMimeType.Length()) |
|
344 { |
|
345 CMSRPContentTypeHeader* contentType = CMSRPContentTypeHeader::NewL( aMimeType ); |
|
346 msrpMessage->SetContentTypeHeader( contentType ); |
|
347 |
|
348 if(aMessage.Length()) |
|
349 { |
|
350 // content of the message |
|
351 HBufC8* contentOfMessage = HBufC8::NewL( aMessage.Length() ); |
|
352 *contentOfMessage = aMessage; |
|
353 |
|
354 msrpMessage->SetContent( contentOfMessage ); |
|
355 } |
|
356 } |
|
357 |
|
358 CleanupStack::Pop(msrpMessage); |
|
359 MSRPLOG( "CMSRPSessionImplementation::CreateMsrpMessageL exit" ) |
|
360 return msrpMessage; |
|
361 } |
|
362 |
|
363 |
|
364 void CMSRPSessionImplementation::SendMessageL( CMSRPMessage* aMessage ) |
|
365 { |
|
366 MSRPLOG( "CMSRPSessionImplementation::SendMessageL enter" ) |
|
367 |
|
368 iSentMessages.AppendL( aMessage ); |
|
369 |
|
370 // making sure the required headers are included |
|
371 if ( !aMessage->FromPathHeader() || !aMessage->ToPathHeader() || !aMessage->MessageIdHeader() ) |
|
372 { |
|
373 User::Leave( KErrArgument ); |
|
374 } |
|
375 |
|
376 CBufSeg* buf1 = CBufSeg::NewL( 256 ); // expandsize 256 |
|
377 CleanupStack::PushL( buf1 ); |
|
378 RBufWriteStream writeStream( *buf1 ); |
|
379 CleanupClosePushL( writeStream ); |
|
380 |
|
381 aMessage->ExternalizeL( writeStream ); |
|
382 writeStream.CommitL(); |
|
383 |
|
384 // MSRP message externalized to buffer, now let's move it to flat buffer |
|
385 if ( buf1->Size() > KMaxLengthOfIncomingMessageExt ) |
|
386 { |
|
387 // invalid message size |
|
388 User::Leave( KErrArgument ); |
|
389 } |
|
390 |
|
391 buf1->Read( 0, iExtMessageBuffer, buf1->Size() ); |
|
392 CleanupStack::PopAndDestroy( 2 ); // buf1, writestream |
|
393 |
|
394 // message creation complete, send the message |
|
395 // synchronously sent the message |
|
396 User::LeaveIfError( iMSRPSession->SendMessage( iExtMessageBuffer ) ); |
|
397 |
|
398 MSRPLOG( "CMSRPSessionImplementation::SendMessageL exit" ) |
|
399 } |
|
400 |
|
401 |
|
402 HBufC8* CMSRPSessionImplementation::SendBufferL( |
|
403 const TDesC8& aMessage, |
|
404 const TDesC8& aMimeType ) |
|
405 { |
|
406 MSRPLOG( "CMSRPSessionImplementation::SendBufferL enter" ) |
|
407 |
|
408 if(aMessage.Length() && !aMimeType.Length()) |
|
409 { |
|
410 User::Leave( KErrArgument ); |
|
411 } |
|
412 |
|
413 CMSRPMessage* msrpMessage = CreateMsrpMessageL( |
|
414 aMessage, iRemoteMsrpPath, iLocalMsrpPath, aMimeType ); |
|
415 CleanupStack::PushL( msrpMessage ); |
|
416 SendMessageL( msrpMessage ); |
|
417 HBufC8* messageId = msrpMessage->MessageIdHeader()->ToTextValueLC(); |
|
418 CleanupStack::Pop(messageId); |
|
419 CleanupStack::Pop( msrpMessage ); |
|
420 MSRPLOG( "CMSRPSessionImplementation::SendBufferL exit" ) |
|
421 return messageId; |
|
422 } |
|
423 |
|
424 |
|
425 void CMSRPSessionImplementation::CancelSendingL( TDesC8& aMessageId ) |
|
426 { |
|
427 MSRPLOG( "CMSRPSessionImplementation::CancelSendingL " ) |
|
428 // then let's send a message to server to cancel sending |
|
429 User::LeaveIfError( iMSRPSession->CancelSending( aMessageId ) ); |
|
430 } |
|
431 |
|
432 |
|
433 void CMSRPSessionImplementation::SendStatusL( TInt aStatus, const TDesC8& aMessageid ) |
|
434 { |
|
435 MSRPLOG2( "CMSRPSessionImplementation::SendStatus = %d", aStatus ) |
|
436 if(isReceiveFile || isSendFile ) |
|
437 { |
|
438 if(isReceiveFile) |
|
439 { |
|
440 iSessionObserver.ReceiveFileNotification( aStatus ); |
|
441 |
|
442 } |
|
443 if(isSendFile) |
|
444 { |
|
445 iSessionObserver.SendFileNotification( aStatus ); |
|
446 } |
|
447 } |
|
448 else |
|
449 { |
|
450 for ( TInt i = 0; i < iSentMessages.Count(); i++ ) |
|
451 { |
|
452 HBufC8* messageid = iSentMessages[ i ]->MessageIdHeader()->ToTextValueLC(); |
|
453 if ( *messageid == aMessageid ) |
|
454 { |
|
455 // match |
|
456 delete iSentMessages[ i ]; |
|
457 iSentMessages.Remove( i ); |
|
458 iSessionObserver.SendResult( aStatus, aMessageid ); |
|
459 CleanupStack::PopAndDestroy(messageid); // messageid from above |
|
460 break; |
|
461 } |
|
462 CleanupStack::PopAndDestroy(messageid); // messageid from above |
|
463 } |
|
464 } |
|
465 |
|
466 MSRPLOG( "CMSRPSessionImplementation::SendStatus exit" ) |
|
467 } |
|
468 |
|
469 void CMSRPSessionImplementation::HandleConnectionErrors( TInt aErrorStatus ) |
|
470 { |
|
471 MSRPLOG2( "CMSRPSessionImplementation::HandleConnectionErrors Error = %d", aErrorStatus ) |
|
472 iSessionObserver.ListenPortFailure(aErrorStatus); |
|
473 |
|
474 } |
|
475 |
|
476 void CMSRPSessionImplementation::SendFileL(const TFileName& aFileName, const TDesC8& aMimeType) |
|
477 { |
|
478 MSRPLOG( "CMSRPSessionImplementation::SendFileL enter" ); |
|
479 |
|
480 if(aFileName.Length() && !aMimeType.Length()) |
|
481 { |
|
482 User::Leave( KErrArgument ); |
|
483 } |
|
484 isSendFile = ETrue; |
|
485 CMSRPMessage* iFile = SetFileParamsL(aFileName,iRemoteMsrpPath, iLocalMsrpPath,aMimeType ); |
|
486 |
|
487 //Set progress indication |
|
488 iFile->SetNotifyProgress(iProgress); |
|
489 |
|
490 CBufSeg* buf = CBufSeg::NewL( 100 ); // expandsize to 100 |
|
491 |
|
492 //todo need to check what's optimal value here |
|
493 CleanupStack::PushL( buf ); |
|
494 RBufWriteStream writeStr( *buf ); |
|
495 CleanupClosePushL( writeStr ); |
|
496 iFile->ExternalizeL( writeStr ); |
|
497 writeStr.CommitL(); |
|
498 |
|
499 // MSRP message externalized to buffer, now let's move it to flat buffer |
|
500 if ( buf->Size() > KMaxLengthOfIncomingMessageExt ) |
|
501 { |
|
502 // invalid message size |
|
503 User::Leave( KErrArgument ); |
|
504 } |
|
505 |
|
506 buf->Read( 0, iExtMessageBuffer, buf->Size() ); |
|
507 CleanupStack::PopAndDestroy( 2 ); // buf, writestream |
|
508 |
|
509 delete iFile; |
|
510 iFile = NULL; |
|
511 // send the filename |
|
512 User::LeaveIfError( iMSRPSession->SendFileL( iExtMessageBuffer ) ); |
|
513 MSRPLOG( "CMSRPSessionImplementation::SendFileL exit" ); |
|
514 } |
|
515 |
|
516 void CMSRPSessionImplementation::ReceiveFileL(const TFileName& aFileName,const TInt aFileSize, const TDesC8& aMimeType) |
|
517 { |
|
518 MSRPLOG( "CMSRPSessionImplementation::ReceiveFileL enter" ); |
|
519 isReceiveFile = ETrue; |
|
520 if(aFileName.Length() && !aMimeType.Length()) |
|
521 { |
|
522 User::Leave( KErrArgument ); |
|
523 } |
|
524 CMSRPMessage* iFile = SetFileParamsL(aFileName,iRemoteMsrpPath, iLocalMsrpPath,aMimeType ); |
|
525 |
|
526 //Set FileSize |
|
527 iFile->SetFileSize(aFileSize); |
|
528 |
|
529 //Set progress indication |
|
530 iFile->SetNotifyProgress(iProgress); |
|
531 |
|
532 CBufSeg* buf = CBufSeg::NewL( 100 ); // expandsize to 100 |
|
533 |
|
534 //todo need to check what's optimal value here |
|
535 CleanupStack::PushL( buf ); |
|
536 RBufWriteStream writeStr( *buf ); |
|
537 CleanupClosePushL( writeStr ); |
|
538 iFile->ExternalizeL( writeStr ); |
|
539 writeStr.CommitL(); |
|
540 |
|
541 // MSRP message externalized to buffer, now let's move it to flat buffer |
|
542 if ( buf->Size() > KMaxLengthOfIncomingMessageExt ) |
|
543 { |
|
544 // invalid message size |
|
545 User::Leave( KErrArgument ); |
|
546 } |
|
547 |
|
548 buf->Read( 0, iExtMessageBuffer, buf->Size() ); |
|
549 CleanupStack::PopAndDestroy( 2 ); // buf, writestream |
|
550 |
|
551 delete iFile; |
|
552 iFile = NULL; |
|
553 // send the filename |
|
554 User::LeaveIfError( iMSRPSession->ReceiveFileL( iExtMessageBuffer ) ); |
|
555 |
|
556 |
|
557 } |
|
558 |
|
559 CMSRPMessage* CMSRPSessionImplementation::SetFileParamsL(const TFileName& aFileName,const TDesC8& aToPath, |
|
560 const TDesC8& aFromPath, |
|
561 const TDesC8& aMimeType ) |
|
562 { |
|
563 MSRPLOG( "CMSRPSessionImplementation::SetFileParamsL enter" ); |
|
564 |
|
565 CMSRPMessage* msrpMessage = new ( ELeave ) CMSRPMessage(); |
|
566 CleanupStack::PushL( msrpMessage ); |
|
567 |
|
568 //set filename |
|
569 msrpMessage->SetFileName( aFileName ); |
|
570 |
|
571 //set to path |
|
572 CMSRPToPathHeader* toPath = CMSRPToPathHeader::DecodeL( aToPath ); |
|
573 msrpMessage->SetToPathHeader( toPath ); |
|
574 |
|
575 //set from path |
|
576 CMSRPFromPathHeader* fromPath = CMSRPFromPathHeader::DecodeL( aFromPath ); |
|
577 msrpMessage->SetFromPathHeader( fromPath ); |
|
578 |
|
579 //set content type |
|
580 if(aMimeType.Length()) |
|
581 { |
|
582 CMSRPContentTypeHeader* contentType = CMSRPContentTypeHeader::NewL( aMimeType ); |
|
583 msrpMessage->SetContentTypeHeader( contentType ); |
|
584 } |
|
585 |
|
586 //set message id header |
|
587 TTime now; |
|
588 now.HomeTime(); |
|
589 TInt64 seed = now.Int64(); |
|
590 // Create a random number as the session ID |
|
591 TInt random = Math::Rand( seed ); |
|
592 TBuf8< 100 > idString; |
|
593 idString.AppendNum( random ); |
|
594 CMSRPMessageIdHeader* messageIdHeader = CMSRPMessageIdHeader::NewL( idString ); |
|
595 msrpMessage->SetMessageIdHeader( messageIdHeader ); |
|
596 |
|
597 // success report header |
|
598 if( iSuccessReport != ENo ) |
|
599 { |
|
600 RStringF string = MSRPStrings::StringF( MSRPStrConsts::EYes ); |
|
601 CMSRPSuccessReportHeader* successReportHeader = CMSRPSuccessReportHeader::NewL( string ); |
|
602 msrpMessage->SetSuccessReportHeader( successReportHeader ); |
|
603 } |
|
604 |
|
605 // failure report header |
|
606 if( iFailureReport != EYes ) |
|
607 { |
|
608 RStringF string; |
|
609 CleanupClosePushL(string); |
|
610 if( iFailureReport == ENo ) |
|
611 { |
|
612 string = MSRPStrings::StringF( MSRPStrConsts::ENo ); |
|
613 } |
|
614 else |
|
615 { |
|
616 string = MSRPStrings::StringF( MSRPStrConsts::EPartial ); |
|
617 } |
|
618 CMSRPFailureReportHeader* failureReportHeader = CMSRPFailureReportHeader::NewL( string ); |
|
619 msrpMessage->SetFailureReportHeader( failureReportHeader ); |
|
620 CleanupStack::PopAndDestroy(); // string |
|
621 } |
|
622 |
|
623 CleanupStack::Pop(msrpMessage); // msrpMessage |
|
624 |
|
625 MSRPLOG( "CMSRPSessionImplementation::SetFileParamsL enter" ); |
|
626 return msrpMessage; |
|
627 } |
|
628 |
|
629 |
|
630 void CMSRPSessionImplementation::NotifyProgress(TBool aFlag) |
|
631 { |
|
632 iProgress = aFlag; |
|
633 } |