realtimenetprots/sipfw/SIP/ConnectionMgr/src/CTcpTransConnecting.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2002-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 // Name          : CTcpTransConnecting.cpp
       
    15 // Part of       : ConnectionMgr
       
    16 // Version       : SIP/6.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "CTcpTransConnecting.h"
       
    23 #include "sipmessage.h"
       
    24 #include "CTransportTcp.h"
       
    25 #include "CReceiverTcp.h"
       
    26 #include "CSender.h"
       
    27 #include "COutgoingData.h"
       
    28 #include "MTransportOwner.h"
       
    29 #include "CommonConsts.h"
       
    30 #include "sipstrings.h"
       
    31 #include "sipstrconsts.h"
       
    32 #include "siperr.h"
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CTcpTransportConnecting::NewL
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CTcpTransportConnecting* CTcpTransportConnecting::NewL(
       
    39     const TSIPTransportParams& aParams)
       
    40 	{
       
    41 	CTcpTransportConnecting* self = NewLC(aParams);
       
    42 	CleanupStack::Pop(self);
       
    43 	return self;
       
    44 	}
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CTcpTransportConnecting::NewLC
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CTcpTransportConnecting* CTcpTransportConnecting::NewLC(
       
    51     const TSIPTransportParams& aParams)
       
    52 	{
       
    53 	CTcpTransportConnecting* self = 
       
    54 	                new (ELeave) CTcpTransportConnecting(aParams);
       
    55 	CleanupStack::PushL(self);
       
    56 	return self;
       
    57 	}
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CTcpTransportConnecting::CancelSend
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 TBool CTcpTransportConnecting::CancelSend(TRequestStatus& aStatus,
       
    64 										  CTransportTcp* aContext)
       
    65 	{
       
    66 	__ASSERT_DEBUG(aContext, User::Panic(_L("Nullpointer"), KErrGeneral));
       
    67 	
       
    68 	return aContext->GetSender()->FindAndCancel(aStatus);
       
    69 	}
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CTcpTransportConnecting::Wait
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CTcpTransportConnecting::Wait(CTransportTcp* /*aContext*/)
       
    76 	{
       
    77 	}
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CTcpTransportConnecting::HandleMessage
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 TBool CTcpTransportConnecting::HandleMessage(RStringF aProtocol, 
       
    84 										 	 const TInetAddr& aRemoteAddr, 
       
    85 										 	 CTransportTcp* aContext)
       
    86 	{
       
    87 	__ASSERT_DEBUG(aContext, User::Panic(_L("Nullpointer"), KErrGeneral));
       
    88 	
       
    89 	TInetAddr connect;
       
    90 	aContext->GetRemoteAddr(connect);
       
    91 	
       
    92 	return (aProtocol == SIPStrings::StringF(SipStrConsts::ETCP) &&
       
    93 	    	connect.CmpAddr(aRemoteAddr));
       
    94 	}
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CTcpTransportConnecting::SendToNetL
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CTcpTransportConnecting::SendToNetL(const TSIPTransportParams& aParams,
       
   101                             CSIPMessage& aMessage,
       
   102 							const TInetAddr& aAddr,
       
   103 							TRequestStatus &aStatus,
       
   104 							TUint aOrigTransport,
       
   105 							CTransportTcp* aContext)
       
   106 	{
       
   107 	__ASSERT_DEBUG(aContext, User::Panic(_L("Nullpointer"), KErrGeneral));
       
   108 	
       
   109 	TBool connect = aContext->GetSender()->SendL(aParams,
       
   110                 	                             aMessage,
       
   111                 							     aAddr,
       
   112                 			                     aOrigTransport,
       
   113                 			                     aStatus,
       
   114                 			                     ETrue,
       
   115                 			                     EFalse);
       
   116 	if ( connect )
       
   117 	    {
       
   118 	    aContext->ConnectSocket();
       
   119 	    }
       
   120 	}
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CTcpTransportConnecting::CancelAllRequests
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CTcpTransportConnecting::CancelAllRequests(CSIPConnection::TState aReason, 
       
   127 												CTransportTcp* aContext)
       
   128 	{
       
   129 	__ASSERT_DEBUG(aContext, User::Panic(_L("Nullpointer"), KErrGeneral));
       
   130 	
       
   131 	aContext->GetSender()->CancelAllRequests(aReason);
       
   132 	}
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CTcpTransportConnecting::ConnectionOpenL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CTcpTransportConnecting::ConnectionOpenL(CTransportTcp* aContext)
       
   139 	{
       
   140 	__ASSERT_DEBUG(aContext, User::Panic(_L("Nullpointer"), KErrGeneral));
       
   141 	
       
   142 	aContext->SetCurrentState(iConnected);
       
   143 	// Possibly update sender socket opts before sending
       
   144 	aContext->GetSender()->SendNextL();
       
   145 	aContext->StartTimerL();
       
   146 	}
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CTcpTransportConnecting::DisconnectedL
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CTcpTransportConnecting::DisconnectedL(CTransportTcp* aContext)
       
   153 	{
       
   154 	__ASSERT_DEBUG(aContext, User::Panic(_L("Nullpointer"), KErrGeneral));
       
   155 	
       
   156 	COutgoingData* data = 0;
       
   157 	CSender* sender = aContext->GetSender();
       
   158 	while ( (data = sender->StoredData()) != 0)
       
   159 		{
       
   160 		if (data->OrigTransport() == KProtocolInetUdp &&
       
   161 			data->Message().IsRequest())
       
   162 			{
       
   163 			data->Sent();
       
   164 			CleanupStack::PushL( data );
       
   165 			aContext->TransportOwner()->ReRouteL(KProtocolInetUdp, 
       
   166 			                                     data);
       
   167 			CleanupStack::Pop( data );
       
   168 			}
       
   169 		else if (data->OrigTransport() == KProtocolInetTcp &&
       
   170 				 !data->Message().IsRequest())
       
   171 			{
       
   172 			data->Sent();
       
   173 			CleanupStack::PushL( data );
       
   174 			aContext->TransportOwner()->ReRouteL(KProtocolInetTcp, 
       
   175 			                                     data);
       
   176 			CleanupStack::Pop( data );
       
   177 			}
       
   178 		else
       
   179 			{
       
   180 			TRequestStatus* stat = data->Status();
       
   181 			User::RequestComplete(stat, KErrSIPTransportFailure);
       
   182 			delete data;
       
   183 			}
       
   184 		}
       
   185 	aContext->Remove();
       
   186 	}
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CTcpTransportConnecting::SetNeighborState
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CTcpTransportConnecting::SetNeighborState(CTcpTransportState* aState)
       
   193 	{
       
   194 	iConnected = aState;
       
   195 	}
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CTcpTransportConnecting::~CTcpTransportConnecting
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 CTcpTransportConnecting::~CTcpTransportConnecting()
       
   202 	{
       
   203 	}
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CTcpTransportConnecting::CTcpTransportConnecting
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 CTcpTransportConnecting::CTcpTransportConnecting(
       
   210     const TSIPTransportParams& aParams) : 
       
   211     CTcpTransportState(aParams)
       
   212 	{
       
   213 	}