Msrp/MsrpClient/src/CMSRPSessionImplementation.cpp
branchMSRP_FrameWork
changeset 58 cdb720e67852
parent 25 505ad3f0ce5c
child 60 7634585a4347
equal deleted inserted replaced
25:505ad3f0ce5c 58:cdb720e67852
    22 #include "MMSRPSessionObserver.h"
    22 #include "MMSRPSessionObserver.h"
    23 #include "CMSRPConnectionListener.h"
    23 #include "CMSRPConnectionListener.h"
    24 #include "CMSRPIncomingListener.h"
    24 #include "CMSRPIncomingListener.h"
    25 #include "CMSRPSendResultListener.h"
    25 #include "CMSRPSendResultListener.h"
    26 #include "CMSRPMessage.h"
    26 #include "CMSRPMessage.h"
       
    27 #include "CMSRPReport.h"
    27 #include "CMSRPToPathHeader.h"
    28 #include "CMSRPToPathHeader.h"
    28 #include "CMSRPFromPathHeader.h"
    29 #include "CMSRPFromPathHeader.h"
    29 #include "CMSRPMessageIdHeader.h"
    30 #include "CMSRPMessageIdHeader.h"
    30 #include "CMSRPSuccessReportHeader.h"
    31 #include "CMSRPSuccessReportHeader.h"
    31 #include "CMsrpFailureReportHeader.h"
    32 #include "CMsrpFailureReportHeader.h"
    32 #include "CMsrpContentTypeHeader.h"
    33 #include "CMsrpContentTypeHeader.h"
    33 #include "CMSRPSessionParams.h"
    34 #include "CMSRPSessionParams.h"
       
    35 #include "CMSRPStatusHeader.h"
       
    36 #include "CMSRPByteRangeHeader.h"
    34 
    37 
    35 
    38 
    36 // SYSTEM INCLUDES
    39 // SYSTEM INCLUDES
    37 #include <e32math.h>
    40 #include <e32math.h>
    38 
    41 
    41 const TInt KMsrpFixedLength=19; // fixed length of a uri
    44 const TInt KMsrpFixedLength=19; // fixed length of a uri
    42 
    45 
    43 
    46 
    44 //  Member Functions
    47 //  Member Functions
    45 
    48 
    46 CMSRPSessionImplementation* CMSRPSessionImplementation::NewL( RMSRP& aRMSRP,
    49 CMSRPSessionImplementation* CMSRPSessionImplementation::NewL( 
    47                                                               MMSRPSessionObserver& aObserver,
    50     RMSRP& aRMSRP,
    48                                                               const TUint aIapId )
    51     MMSRPSessionObserver& aObserver,
       
    52     const TUint aIapId,
       
    53     const TDesC8& aSessionId )
    49 	{
    54 	{
    50 	MSRPLOG("CMSRPSessionImplementation::NewL");
    55 	MSRPLOG("CMSRPSessionImplementation::NewL");
    51 	CMSRPSessionImplementation *self = CMSRPSessionImplementation::NewLC( aRMSRP, aObserver, aIapId );
    56 	CMSRPSessionImplementation *self = CMSRPSessionImplementation::NewLC( 
       
    57 	        aRMSRP, aObserver, aIapId, aSessionId );
    52 
    58 
    53 	CleanupStack::Pop(self);
    59 	CleanupStack::Pop(self);
    54 	return self;
    60 	return self;
    55 	}
    61 	}
    56 
    62 
    57 
    63 
    58 CMSRPSessionImplementation* CMSRPSessionImplementation::NewLC( RMSRP& aRMSRP,
    64 CMSRPSessionImplementation* CMSRPSessionImplementation::NewLC( 
    59                                                                MMSRPSessionObserver& aObserver,
    65     RMSRP& aRMSRP,
    60                                                                const TUint aIapId )
    66     MMSRPSessionObserver& aObserver,
       
    67     const TUint aIapId,
       
    68     const TDesC8& aSessionId )
    61     {
    69     {
    62     MSRPLOG("CMSRPSessionImplementation::NewLC");
    70     MSRPLOG("CMSRPSessionImplementation::NewLC");
    63     CMSRPSessionImplementation *self = new (ELeave) CMSRPSessionImplementation( aRMSRP, aObserver );                                                            
    71     CMSRPSessionImplementation *self = new (ELeave) CMSRPSessionImplementation( aRMSRP, aObserver );                                                            
    64 
    72 
    65     CleanupStack::PushL(self);                                                       
    73     CleanupStack::PushL(self);                                                       
    66     self->ConstructL( aIapId );
    74     self->ConstructL( aIapId, aSessionId );
    67     return self;
    75     return self;
    68     }
    76     }
    69 
    77 
    70 CMSRPSessionImplementation::CMSRPSessionImplementation( RMSRP& aRMSRP,
    78 CMSRPSessionImplementation::CMSRPSessionImplementation( RMSRP& aRMSRP,
    71                                                         MMSRPSessionObserver& aObserver )
    79                                                         MMSRPSessionObserver& aObserver )
    76     {
    84     {
    77     MSRPLOG("CMSRPSessionImplementation::Ctor");
    85     MSRPLOG("CMSRPSessionImplementation::Ctor");
    78 	}
    86 	}
    79 
    87 
    80 
    88 
    81 void CMSRPSessionImplementation::ConstructL( const TUint aIapId )
    89 void CMSRPSessionImplementation::ConstructL( const TUint aIapId, const TDesC8& aSessionId )
    82 	{
    90 	{
    83 	MSRPLOG("CMSRPSessionImplementation::ConstructL enter");
    91 	MSRPLOG("CMSRPSessionImplementation::ConstructL enter");
    84 	
    92 	
    85 	MSRPStrings::OpenL();
    93 	MSRPStrings::OpenL();
    86 	iMSRPSession = new ( ELeave ) RMSRPSession();
    94 	iMSRPSession = new ( ELeave ) RMSRPSession();
    87 	    
    95 	    
    88 	User::LeaveIfError(iMSRPSession->CreateServerSubSession( iRMSRP, aIapId ) );
    96 	User::LeaveIfError(iMSRPSession->CreateServerSubSession( iRMSRP, aIapId, aSessionId ) );
    89 	MSRPLOG("Sub session opened successfully!");
    97 	MSRPLOG("Sub session opened successfully!");
    90 		
    98 		
    91 	RBuf8 sessionID;
       
    92 	sessionID.CreateL( KMaxLengthOfSessionId );
       
    93 	CleanupClosePushL( sessionID );
       
    94 	
       
    95 	RBuf8 localHost;
    99 	RBuf8 localHost;
    96 	localHost.CreateL( KMaxLengthOfHost );
   100 	localHost.CreateL( KMaxLengthOfHost );
    97 	CleanupClosePushL( localHost );
   101 	CleanupClosePushL( localHost );
    98 	
   102 	
    99 	iMSRPSession->GetLocalPathL( localHost, sessionID );
   103 	iMSRPSession->GetLocalPathL( localHost );
   100 	
   104 	
   101 	iLocalMsrpPath.CreateL( KMsrpUriScheme, KMsrpFixedLength + localHost.Length() + sessionID.Length() );
   105 	iLocalMsrpPath.CreateL( KMsrpUriScheme, KMsrpFixedLength + localHost.Length() + aSessionId.Length() );
   102 		
   106 		
   103 	iLocalMsrpPath.Append( localHost );
   107 	iLocalMsrpPath.Append( localHost );
   104 	iLocalMsrpPath.Append( KColon );
   108 	iLocalMsrpPath.Append( KColon );
   105 	iLocalMsrpPath.AppendNum( KMsrpPort );
   109 	iLocalMsrpPath.AppendNum( KMsrpPort );
   106 	iLocalMsrpPath.Append( KForwardSlash );   
   110 	iLocalMsrpPath.Append( KForwardSlash );   
   107 	iLocalMsrpPath.Append( sessionID );
   111 	iLocalMsrpPath.Append( aSessionId );
   108 	iLocalMsrpPath.Append( KSemicolon );
   112 	iLocalMsrpPath.Append( KSemicolon );
   109 	iLocalMsrpPath.Append( KTransport );
   113 	iLocalMsrpPath.Append( KTransport );
   110 	
   114 	
   111 	
   115 	
   112 	iConnectionListener = CMSRPConnectionListener::NewL(
   116 	iConnectionListener = CMSRPConnectionListener::NewL(
   113 	        *this, *iMSRPSession );
   117 	        *this, *iMSRPSession );
       
   118 	iSendResultListener = CMSRPSendResultListener::NewL(
       
   119 	        *this, *iMSRPSession, aSessionId );
   114 	iIncomingListener = CMSRPIncomingListener::NewL(
   120 	iIncomingListener = CMSRPIncomingListener::NewL(
   115 	        *this, *iMSRPSession );
   121             *this, *iMSRPSession );
   116 	iSendResultListener = CMSRPSendResultListener::NewL(
       
   117 	        *this, *iMSRPSession, sessionID );
       
   118 	
   122 	
   119 	CleanupStack::PopAndDestroy(2); //sessionID and localHost
   123 	CleanupStack::PopAndDestroy( ); // localHost
   120 	MSRPLOG("CMSRPSessionImplementation::ConstructL exit");
   124 	MSRPLOG("CMSRPSessionImplementation::ConstructL exit");
   121 	}
   125 	}
   122 
   126 
   123 
   127 
   124 CMSRPSessionImplementation::~CMSRPSessionImplementation()
   128 CMSRPSessionImplementation::~CMSRPSessionImplementation()
   125     {
   129     {
   126     MSRPLOG("CMSRPSessionImplementation::Dtor Entered");
   130     MSRPLOG("CMSRPSessionImplementation::Dtor Entered");
   127         
   131     
   128     MSRPStrings::Close();
   132     MSRPStrings::Close();
   129     iLocalMsrpPath.Close();
   133     iLocalMsrpPath.Close();
   130     iRemoteMsrpPath.Close();
   134     iRemoteMsrpPath.Close();
   131     
   135     
   132     delete iConnectionListener;
   136     delete iConnectionListener;
   215     MSRPLOG("CMSRPSessionImplementation::ListenL exit");
   219     MSRPLOG("CMSRPSessionImplementation::ListenL exit");
   216     }
   220     }
   217 
   221 
   218 
   222 
   219 void CMSRPSessionImplementation::ConnectionEstablishedL( TInt aStatus )
   223 void CMSRPSessionImplementation::ConnectionEstablishedL( TInt aStatus )
   220     {
   224     {    
   221     
       
   222     MSRPLOG("CMSRPSessionImplementation::ConnectionEstablished enter");
   225     MSRPLOG("CMSRPSessionImplementation::ConnectionEstablished enter");
   223     
   226     
   224     iSessionObserver.ConnectStatus(aStatus);
   227     iSessionObserver.ConnectStatus(aStatus);
   225     if ( aStatus == KErrNone )
   228     if ( aStatus == KErrNone )
   226         {
   229         {
   227         // start listening to incoming messages directed to this session
   230         // start listening to incoming messages directed to this session
   228         iIncomingListener->ListenMessages( );
   231         iIncomingListener->ListenMessages( );
   229 
   232 
   230         // start listening when message has been sent,  to responses
   233         // start listening when message has been sent,  to responses
   231         iSendResultListener->ListenSendResultL( );                
   234         iSendResultListener->ListenSendResultL( );        
   232         }
   235         }
   233     
   236     
   234     MSRPLOG("CMSRPSessionImplementation::ConnectionEstablished exit");
   237     MSRPLOG("CMSRPSessionImplementation::ConnectionEstablished exit");
   235     }
   238     }
   236     
   239     
   246     if ( CMSRPMessage::IsMessage( aIncomingMessage ) )
   249     if ( CMSRPMessage::IsMessage( aIncomingMessage ) )
   247         {
   250         {
   248         CMSRPMessage* message = NULL;
   251         CMSRPMessage* message = NULL;
   249         message = CMSRPMessage::InternalizeL( readStream );
   252         message = CMSRPMessage::InternalizeL( readStream );
   250         CleanupStack::PushL(message);
   253         CleanupStack::PushL(message);
       
   254         MSRPLOG2( "CMSRPSessionImplementation::HandleIncomingMessageL, content = %d", message->IsContent()  )
       
   255         MSRPLOG2( "CMSRPSessionImplementation::HandleIncomingMessageL, FN = %S", &message->GetFileName()  )
   251         
   256         
   252         HBufC8* messageContent = NULL;
   257         HBufC8* contentType = NULL;
   253         if(message->IsContent())
   258         if( message->IsContent() )
   254             {
   259             {
   255             messageContent = HBufC8::NewL(message->Content().Length());
   260             HBufC8* messageContent = NULL;
   256             CleanupStack::PushL( messageContent );
   261             if ( message->Content().Length() )
   257             *messageContent = message->Content();
   262                 {
       
   263                 messageContent = HBufC8::NewL(message->Content().Length());
       
   264                 CleanupStack::PushL( messageContent );
       
   265                 *messageContent = message->Content();
       
   266                 }
       
   267             else
       
   268                 {
       
   269                 messageContent = HBufC8::NewL(KNullDesC8().Length());
       
   270                 CleanupStack::PushL( messageContent );
       
   271                 *messageContent = KNullDesC8();
       
   272                 }
       
   273             
       
   274             if( message->ContentTypeHeader() )
       
   275                 {
       
   276                 contentType = message->ContentTypeHeader()->ToTextValueLC();
       
   277                 CleanupStack::Pop();
       
   278                 }
       
   279 
       
   280             iSessionObserver.IncomingMessageInBuffer( messageContent, contentType, aStatus );
       
   281             CleanupStack::Pop( messageContent );
   258             }
   282             }
   259         else
   283         else
   260             {
   284             {
   261             messageContent = HBufC8::NewL(KNullDesC8().Length());
   285             if( message->ContentTypeHeader() )
   262             CleanupStack::PushL( messageContent );
   286                 {
   263             *messageContent = KNullDesC8();
   287                 contentType = message->ContentTypeHeader()->ToTextValueLC();
   264             }
   288                 CleanupStack::Pop();
   265 
   289                 }
   266         iSessionObserver.IncomingMessage( messageContent, aStatus );
   290             iSessionObserver.IncomingMessageInFile( message->GetFileName(), contentType, aStatus );
   267         CleanupStack::Pop( messageContent );
   291             }
   268         CleanupStack::PopAndDestroy(message);
   292         CleanupStack::PopAndDestroy( message );
       
   293         }
       
   294     else if ( CMSRPReport::IsReport( aIncomingMessage ) )
       
   295         {
       
   296         CMSRPReport* report = CMSRPReport::InternalizeL( readStream );
       
   297         MSRPLOG2( "CMSRPSessionImplementation::HandleIncomingMessageL, status = %d", report->StatusHeader()->StatusCode() )
       
   298         MSRPLOG2( "CMSRPSessionImplementation::HandleIncomingMessageL, startpos = %d", report->ByteRangeHeader()->StartPosition() )
       
   299         MSRPLOG2( "CMSRPSessionImplementation::HandleIncomingMessageL, endpos = %d", report->ByteRangeHeader()->EndPosition() )
       
   300         MSRPLOG2( "CMSRPSessionImplementation::HandleIncomingMessageL, total = %d", report->ByteRangeHeader()->TotalLength() )
       
   301 
       
   302         iSessionObserver.IncomingReport(
       
   303             report->StatusHeader()->StatusCode(),
       
   304             report->ByteRangeHeader()->StartPosition(),
       
   305             report->ByteRangeHeader()->EndPosition(),
       
   306             report->ByteRangeHeader()->TotalLength() );
       
   307         delete report;
   269         }
   308         }
   270     else
   309     else
   271         {
   310         {
   272         User::Leave( KErrArgument );
   311         User::Leave( KErrArgument );
   273         }
   312         }
   274     
   313     
   275     MSRPLOG( "CMSRPSessionImplementation::HandleIncomingMessageL exit" )
   314     MSRPLOG( "CMSRPSessionImplementation::HandleIncomingMessageL exit" )
   276     }
   315     }
   277 
   316 
   278 void CMSRPSessionImplementation::ReceiveProgress(TInt aBytesReceived, TInt aTotalBytes)
   317 
   279     {
   318 void CMSRPSessionImplementation::ReceiveProgress( 
   280     iSessionObserver.FileReceiveProgress(aBytesReceived, aTotalBytes);
   319     const TDesC8& aMessageId, 
   281     }
   320     TInt aBytesReceived, 
   282 
   321     TInt aTotalBytes )
   283 void CMSRPSessionImplementation::SendProgress(TInt aBytesSent, TInt aTotalBytes)
   322     {
   284     {
   323     iSessionObserver.ReceiveProgress( aMessageId, aBytesReceived, aTotalBytes);
   285     iSessionObserver.FileSendProgress(aBytesSent, aTotalBytes);    
   324     }
   286     }
   325 
       
   326 
       
   327 void CMSRPSessionImplementation::SendProgress( 
       
   328     const TDesC8& aMessageId,
       
   329     TInt aBytesSent, 
       
   330     TInt aTotalBytes )
       
   331     {
       
   332     iSessionObserver.SendProgress( aMessageId, aBytesSent, aTotalBytes);    
       
   333     }
       
   334 
   287 
   335 
   288 CMSRPMessage* CMSRPSessionImplementation::CreateMsrpMessageL(
   336 CMSRPMessage* CMSRPSessionImplementation::CreateMsrpMessageL(
   289     const TDesC8& aMessage, const TDesC8& aToPath,
   337     const TDesC8& aMessage, const TDesC8& aToPath,
   290     const TDesC8& aFromPath, const TDesC8& aMimeType )
   338     const TDesC8& aFromPath, const TDesC8& aMimeType )
   291     {
   339     {
   343     if(aMimeType.Length())
   391     if(aMimeType.Length())
   344         {
   392         {
   345         CMSRPContentTypeHeader* contentType = CMSRPContentTypeHeader::NewL( aMimeType );
   393         CMSRPContentTypeHeader* contentType = CMSRPContentTypeHeader::NewL( aMimeType );
   346         msrpMessage->SetContentTypeHeader( contentType );
   394         msrpMessage->SetContentTypeHeader( contentType );
   347         
   395         
   348         if(aMessage.Length())
   396         if( aMessage.Length() )
   349             {
   397             {
   350             // content of the message
   398             // content of the message
   351             HBufC8* contentOfMessage = HBufC8::NewL( aMessage.Length() );
   399             HBufC8* contentOfMessage = HBufC8::NewL( aMessage.Length() );
   352             *contentOfMessage = aMessage;
   400             *contentOfMessage = aMessage;
   353 
   401 
   354             msrpMessage->SetContent( contentOfMessage );
   402             msrpMessage->SetContent( contentOfMessage );
   355             }        
   403             }
   356         }
   404         }
   357     
   405     
   358     CleanupStack::Pop(msrpMessage);
   406     CleanupStack::Pop(msrpMessage);
   359     MSRPLOG( "CMSRPSessionImplementation::CreateMsrpMessageL exit" )
   407     MSRPLOG( "CMSRPSessionImplementation::CreateMsrpMessageL exit" )
   360     return msrpMessage;
   408     return msrpMessage;
   371     if ( !aMessage->FromPathHeader() || !aMessage->ToPathHeader() || !aMessage->MessageIdHeader() )
   419     if ( !aMessage->FromPathHeader() || !aMessage->ToPathHeader() || !aMessage->MessageIdHeader() )
   372         {
   420         {
   373         User::Leave( KErrArgument );
   421         User::Leave( KErrArgument );
   374         }
   422         }
   375 
   423 
   376     CBufSeg* buf1 = CBufSeg::NewL( 256 ); // expandsize 256
   424     CBufSeg* buf1 = CBufSeg::NewL( KBufExpandSize );
   377     CleanupStack::PushL( buf1 );
   425     CleanupStack::PushL( buf1 );
   378     RBufWriteStream writeStream( *buf1 );
   426     RBufWriteStream writeStream( *buf1 );
   379     CleanupClosePushL( writeStream );
   427     CleanupClosePushL( writeStream );
   380 
   428 
   381     aMessage->ExternalizeL( writeStream );
   429     aMessage->ExternalizeL( writeStream );
   402 HBufC8* CMSRPSessionImplementation::SendBufferL(
   450 HBufC8* CMSRPSessionImplementation::SendBufferL(
   403     const TDesC8& aMessage,
   451     const TDesC8& aMessage,
   404     const TDesC8& aMimeType )
   452     const TDesC8& aMimeType )
   405     {
   453     {
   406     MSRPLOG( "CMSRPSessionImplementation::SendBufferL enter" )
   454     MSRPLOG( "CMSRPSessionImplementation::SendBufferL enter" )
   407     
       
   408     if(aMessage.Length() && !aMimeType.Length())
       
   409         {
       
   410         User::Leave( KErrArgument );
       
   411         }
       
   412     
   455     
   413     CMSRPMessage* msrpMessage = CreateMsrpMessageL(
   456     CMSRPMessage* msrpMessage = CreateMsrpMessageL(
   414                                 aMessage, iRemoteMsrpPath, iLocalMsrpPath, aMimeType );
   457                                 aMessage, iRemoteMsrpPath, iLocalMsrpPath, aMimeType );
   415     CleanupStack::PushL( msrpMessage );
   458     CleanupStack::PushL( msrpMessage );
   416     SendMessageL( msrpMessage );
   459     SendMessageL( msrpMessage );
   427     MSRPLOG( "CMSRPSessionImplementation::CancelSendingL " )
   470     MSRPLOG( "CMSRPSessionImplementation::CancelSendingL " )
   428     // then let's send a message to server to cancel sending
   471     // then let's send a message to server to cancel sending
   429     User::LeaveIfError( iMSRPSession->CancelSending( aMessageId ) );
   472     User::LeaveIfError( iMSRPSession->CancelSending( aMessageId ) );
   430     }
   473     }
   431 
   474 
       
   475 void CMSRPSessionImplementation::CancelReceivingL( TDesC8& aMessageId )
       
   476     {
       
   477     MSRPLOG( "CMSRPSessionImplementation::CancelReceivingL " )
       
   478     // then let's send a message to server to cancel receiving
       
   479     User::LeaveIfError( iMSRPSession->CancelReceiving( aMessageId ) );
       
   480     }
   432 
   481 
   433 void CMSRPSessionImplementation::SendStatusL( TInt aStatus, const TDesC8& aMessageid )
   482 void CMSRPSessionImplementation::SendStatusL( TInt aStatus, const TDesC8& aMessageid )
   434     {
   483     {
   435     MSRPLOG2( "CMSRPSessionImplementation::SendStatus = %d", aStatus )
   484     MSRPLOG2( "CMSRPSessionImplementation::SendStatus = %d", aStatus )
   436     if(isReceiveFile || isSendFile )
   485     for ( TInt i = 0; i < iSentMessages.Count(); i++ )
   437         {
   486         {
   438         if(isReceiveFile)
   487         HBufC8* messageid = iSentMessages[ i ]->MessageIdHeader()->ToTextValueLC();
   439             {
   488         if ( *messageid == aMessageid )
   440             iSessionObserver.ReceiveFileNotification( aStatus );
   489             {
   441            
   490             // match
   442             }
   491             delete iSentMessages[ i ];
   443         if(isSendFile)
   492             iSentMessages.Remove( i );
   444             {
   493             iSessionObserver.SendResult( aStatus, aMessageid );
   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
   494             CleanupStack::PopAndDestroy(messageid); // messageid from above
   463             }
   495             break;
   464         }
   496             }
   465 
   497         CleanupStack::PopAndDestroy(messageid); // messageid from above
       
   498         }
       
   499         
   466     MSRPLOG( "CMSRPSessionImplementation::SendStatus exit" )
   500     MSRPLOG( "CMSRPSessionImplementation::SendStatus exit" )
   467     }
   501     }
   468 
   502 
   469 void CMSRPSessionImplementation::HandleConnectionErrors( TInt aErrorStatus )
   503 void CMSRPSessionImplementation::HandleConnectionErrors( TInt aErrorStatus )
   470     {
   504     {
   471     MSRPLOG2( "CMSRPSessionImplementation::HandleConnectionErrors Error = %d", aErrorStatus )
   505     MSRPLOG2( "CMSRPSessionImplementation::HandleConnectionErrors Error = %d", aErrorStatus )
   472     iSessionObserver.ListenPortFailure(aErrorStatus);  
   506     iSessionObserver.ConnectStatus(aErrorStatus);      
   473     
   507     }
   474     }
   508 
   475 
   509 
   476 void CMSRPSessionImplementation::SendFileL(const TFileName& aFileName, const TDesC8& aMimeType)
   510 HBufC8* CMSRPSessionImplementation::SendFileL(const TFileName& aFileName, const TDesC8& aMimeType)
   477     {
   511     {
   478     MSRPLOG( "CMSRPSessionImplementation::SendFileL enter" );
   512     MSRPLOG( "CMSRPSessionImplementation::SendFileL enter" );   
   479    
   513     
   480     if(aFileName.Length() && !aMimeType.Length())
   514     if(aFileName.Length() && !aMimeType.Length())
   481         {
   515         {
   482         User::Leave( KErrArgument );
   516         User::Leave( KErrArgument );
   483         }
   517         }
   484      isSendFile = ETrue;
   518     CMSRPMessage* file = SetFileParamsL( aFileName,iRemoteMsrpPath, iLocalMsrpPath,aMimeType );
   485     CMSRPMessage* iFile = SetFileParamsL(aFileName,iRemoteMsrpPath, iLocalMsrpPath,aMimeType );
   519     CleanupStack::PushL( file );
   486     
   520     
   487      //Set progress indication
   521     iSentMessages.AppendL( file );
   488     iFile->SetNotifyProgress(iProgress);
   522     CleanupStack::Pop(); // file
   489      
   523     
   490     CBufSeg* buf = CBufSeg::NewL( 100 ); // expandsize to 100 
   524     CBufSeg* buf = CBufSeg::NewL( KBufExpandSize ); 
   491     
   525     
   492     //todo need to check what's optimal value here
   526     //todo need to check what's optimal value here
   493     CleanupStack::PushL( buf );
   527     CleanupStack::PushL( buf );
   494     RBufWriteStream writeStr( *buf );
   528     RBufWriteStream writeStr( *buf );
   495     CleanupClosePushL( writeStr );
   529     CleanupClosePushL( writeStr );
   496     iFile->ExternalizeL( writeStr );
   530     file->ExternalizeL( writeStr );
   497     writeStr.CommitL();
   531     writeStr.CommitL();
   498     
   532     
   499     // MSRP message externalized to buffer, now let's move it to flat buffer
   533     // MSRP message externalized to buffer, now let's move it to flat buffer
   500     if ( buf->Size() > KMaxLengthOfIncomingMessageExt )
   534     if ( buf->Size() > KMaxLengthOfIncomingMessageExt )
   501         {
   535         {
   502         // invalid message size
   536         // invalid message size
   503         User::Leave( KErrArgument );
   537         User::Leave( KErrArgument );
   504         }
   538         }
   505 
   539 
   506     buf->Read( 0, iExtMessageBuffer, buf->Size() );
   540     buf->Read( 0, iExtMessageBuffer, buf->Size() );
       
   541     HBufC8* messageId = file->MessageIdHeader()->ToTextValueLC();
       
   542     CleanupStack::Pop(); // messageid
   507     CleanupStack::PopAndDestroy( 2 ); // buf, writestream
   543     CleanupStack::PopAndDestroy( 2 ); // buf, writestream
   508    
   544     CleanupStack::PushL( messageId );
   509     delete iFile;
   545        
   510 	iFile = NULL;
       
   511     // send the filename
   546     // send the filename
   512    User::LeaveIfError( iMSRPSession->SendFileL( iExtMessageBuffer ) );
   547     User::LeaveIfError( iMSRPSession->SendMessage( iExtMessageBuffer ) );
   513    MSRPLOG( "CMSRPSessionImplementation::SendFileL exit" ); 
   548     CleanupStack::Pop( messageId ); 
       
   549     
       
   550     MSRPLOG( "CMSRPSessionImplementation::SendFileL exit" );
       
   551     return messageId;
   514     }  
   552     }  
   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 
   553 
   559 CMSRPMessage* CMSRPSessionImplementation::SetFileParamsL(const TFileName& aFileName,const TDesC8& aToPath,
   554 CMSRPMessage* CMSRPSessionImplementation::SetFileParamsL(const TFileName& aFileName,const TDesC8& aToPath,
   560                                                         const TDesC8& aFromPath, 
   555                                                         const TDesC8& aFromPath, 
   561                                                         const TDesC8& aMimeType )
   556                                                         const TDesC8& aMimeType )
   562     {
   557     {
   563       MSRPLOG( "CMSRPSessionImplementation::SetFileParamsL enter" );
   558     MSRPLOG( "CMSRPSessionImplementation::SetFileParamsL enter" );
   564     
   559     
   565       CMSRPMessage* msrpMessage = new ( ELeave ) CMSRPMessage();
   560     CMSRPMessage* msrpMessage = new ( ELeave ) CMSRPMessage();
   566       CleanupStack::PushL( msrpMessage );
   561     CleanupStack::PushL( msrpMessage );
   567     
   562     
   568       //set filename
   563     //set filename
   569       msrpMessage->SetFileName( aFileName );
   564     msrpMessage->SetFileName( aFileName );
   570     
   565     
   571       //set to path
   566     //set to path
   572       CMSRPToPathHeader* toPath = CMSRPToPathHeader::DecodeL( aToPath );
   567     CMSRPToPathHeader* toPath = CMSRPToPathHeader::DecodeL( aToPath );
   573       msrpMessage->SetToPathHeader( toPath );
   568     msrpMessage->SetToPathHeader( toPath );
   574 
   569     
   575       //set from path
   570     //set from path
   576       CMSRPFromPathHeader* fromPath = CMSRPFromPathHeader::DecodeL( aFromPath );
   571     CMSRPFromPathHeader* fromPath = CMSRPFromPathHeader::DecodeL( aFromPath );
   577       msrpMessage->SetFromPathHeader( fromPath );
   572     msrpMessage->SetFromPathHeader( fromPath );
   578 
   573     
   579       //set content type
   574     //set content type
   580       if(aMimeType.Length())
   575     if(aMimeType.Length())
   581           {
   576       {
   582           CMSRPContentTypeHeader* contentType = CMSRPContentTypeHeader::NewL( aMimeType );
   577       CMSRPContentTypeHeader* contentType = CMSRPContentTypeHeader::NewL( aMimeType );
   583           msrpMessage->SetContentTypeHeader( contentType );
   578       msrpMessage->SetContentTypeHeader( contentType );
   584           }
   579       }
   585       
   580     
   586       //set  message id header
   581     //set  message id header
   587       TTime now;
   582     TTime now;
   588       now.HomeTime();
   583     now.HomeTime();
   589       TInt64 seed = now.Int64();
   584     TInt64 seed = now.Int64();
   590       // Create a random number as the session ID
   585     // Create a random number as the session ID
   591       TInt random = Math::Rand( seed );
   586     TInt random = Math::Rand( seed );
   592       TBuf8< 100 > idString;
   587     TBuf8< 100 > idString;
   593       idString.AppendNum( random );
   588     idString.AppendNum( random );
   594       CMSRPMessageIdHeader* messageIdHeader = CMSRPMessageIdHeader::NewL( idString );
   589     CMSRPMessageIdHeader* messageIdHeader = CMSRPMessageIdHeader::NewL( idString );
   595       msrpMessage->SetMessageIdHeader( messageIdHeader );
   590     msrpMessage->SetMessageIdHeader( messageIdHeader );
   596       
   591       
   597       // success report header
   592       // success report header
   598         if( iSuccessReport != ENo )
   593     if( iSuccessReport != ENo )
   599             {
   594         {
   600             RStringF string = MSRPStrings::StringF( MSRPStrConsts::EYes );
   595         RStringF string = MSRPStrings::StringF( MSRPStrConsts::EYes );
   601             CMSRPSuccessReportHeader* successReportHeader = CMSRPSuccessReportHeader::NewL( string );
   596         CMSRPSuccessReportHeader* successReportHeader = CMSRPSuccessReportHeader::NewL( string );
   602             msrpMessage->SetSuccessReportHeader( successReportHeader );
   597         msrpMessage->SetSuccessReportHeader( successReportHeader );
   603             }
   598         }
   604         
   599     
   605         // failure report header
   600     // failure report header
   606         if( iFailureReport != EYes )
   601     if( iFailureReport != EYes )
   607             {
   602         {
   608             RStringF string;
   603         RStringF string;
   609             CleanupClosePushL(string);
   604         CleanupClosePushL(string);
   610             if( iFailureReport == ENo )
   605         if( iFailureReport == ENo )
   611                 {
   606             {
   612                 string = MSRPStrings::StringF( MSRPStrConsts::ENo );
   607             string = MSRPStrings::StringF( MSRPStrConsts::ENo );
   613                 }
   608             }
   614             else
   609         else
   615                 {
   610             {
   616                 string = MSRPStrings::StringF( MSRPStrConsts::EPartial );
   611             string = MSRPStrings::StringF( MSRPStrConsts::EPartial );
   617                 }
   612             }
   618             CMSRPFailureReportHeader* failureReportHeader = CMSRPFailureReportHeader::NewL( string );
   613         CMSRPFailureReportHeader* failureReportHeader = CMSRPFailureReportHeader::NewL( string );
   619             msrpMessage->SetFailureReportHeader( failureReportHeader );
   614         msrpMessage->SetFailureReportHeader( failureReportHeader );
   620             CleanupStack::PopAndDestroy(); // string
   615         CleanupStack::PopAndDestroy(); // string
   621             }
   616         }
   622       
   617     
   623           CleanupStack::Pop(msrpMessage); // msrpMessage
   618     CleanupStack::Pop(msrpMessage); // msrpMessage
   624          
   619          
   625      MSRPLOG( "CMSRPSessionImplementation::SetFileParamsL enter" );
   620     MSRPLOG( "CMSRPSessionImplementation::SetFileParamsL enter" );
   626 	 return msrpMessage;
   621 	return msrpMessage;
   627     }
   622     }
   628 
   623 
   629 
   624 
   630 void CMSRPSessionImplementation::NotifyProgress(TBool aFlag)
   625 void CMSRPSessionImplementation::NotifyProgress(TBool aFlag)
   631     {
   626     {
   632      iProgress = aFlag;
   627     iMSRPSession->SetProgressReports( aFlag );
   633     }
   628     }
       
   629 
       
   630 // End of file