realtimenetprots/sipfw/SIP/sipapi/src/SipConnectionImplementation.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2008-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          : SipConnectionImplementation.cpp
       
    15 // Part of       : SIPAPI
       
    16 // Version       : SIP/5.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "SipAssert.h"
       
    22 #include "SipConnectionImplementation.h"
       
    23 #include "sipconnectionobserver.h"
       
    24 #include "sipclientconnection.h"
       
    25 #include "sip.h"
       
    26 #include "SipImplementation.h"
       
    27 #include "siperr.h"
       
    28 #include "sipinternalerr.h"
       
    29 #include "sipmessageelements.h"
       
    30 #include "siprequestelements.h"
       
    31 #include "sipresponseelements.h"
       
    32 #include "sipclienttransaction.h"
       
    33 #include "sipservertransaction.h"
       
    34 #include "RegBindingImplementation.h"
       
    35 #include "SipDialogImplementation.h"
       
    36 #include "siprefresh.h"
       
    37 #include "sipconnectioncallback.h"
       
    38 #include "sipstrings.h"
       
    39 #include "sipstrconsts.h"
       
    40 
       
    41 #ifdef CPPUNIT_TEST
       
    42 #include "TestCleanupStack.h"
       
    43 #endif
       
    44 
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CSIPConnectionImplementation::NewL
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CSIPConnectionImplementation*
       
    51 CSIPConnectionImplementation::NewL(CSIP& aSIP,
       
    52 								   CSIPConnection& aConnection,
       
    53 					 			   TUint32 aIapId,
       
    54 					 			   MSIPConnectionObserver& aObserver)
       
    55 	{
       
    56     CSIPConnectionImplementation* self =
       
    57     	new (ELeave) CSIPConnectionImplementation(aSIP,
       
    58     											  aConnection,
       
    59     											  aIapId,
       
    60     											  aObserver);
       
    61     CleanupStack::PushL(self);
       
    62     self->ConstructL();
       
    63     CleanupStack::Pop(self);
       
    64     return self;
       
    65 	}
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CSIPConnectionImplementation::CSIPConnectionImplementation
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CSIPConnectionImplementation::CSIPConnectionImplementation(CSIP& aSIP,
       
    72 							   CSIPConnection& aConnection,
       
    73                                TUint32 aIapId,
       
    74                                MSIPConnectionObserver& aObserver) :
       
    75     iSIP(&aSIP),
       
    76     iConnection(aConnection),
       
    77     iIapId(aIapId),
       
    78     iObserver(aObserver)
       
    79 #ifdef CPPUNIT_TEST
       
    80     , iRegistrations(1),
       
    81     iDialogs(1),
       
    82     iTransactions(1),
       
    83     iRefreshes(1)
       
    84 #endif
       
    85     {
       
    86 	}
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CSIPConnectionImplementation::ConstructL
       
    90 // Pass "*this" to AddConnectionL which asks for CSIPConnection. Can't pass
       
    91 // CSIPConnection, as AddConnectionL asks for CSIPConnection::iImplementation
       
    92 // which is NULL, as execution is inside CSIPConnectionImplementation::NewL.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CSIPConnectionImplementation::ConstructL()
       
    96 	{
       
    97 	CheckCSipL();
       
    98 
       
    99     iCallbackInfo = CConnectionCallback::NewL();
       
   100     iClientConnection =
       
   101     	CSIPClientConnection::NewL(iSIP->Implementation().SIPClient(),
       
   102                                    *this,
       
   103                                    iIapId);	
       
   104 	iSIP->Implementation().AddConnectionL(*this, iIapId);
       
   105 	}
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CSIPConnectionImplementation::~CSIPConnectionImplementation
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 CSIPConnectionImplementation::~CSIPConnectionImplementation()
       
   112 	{	
       
   113     if (iSIP)
       
   114         {        
       
   115         iSIP->Implementation().RemoveConnection(iConnection);
       
   116         }    
       
   117 
       
   118     TInt i = 0;
       
   119     for (i = 0; i < iRegistrations.Count(); i++)
       
   120         {
       
   121         iRegistrations[i]->ConnectionDeleted();
       
   122         }
       
   123     iRegistrations.Reset();
       
   124     
       
   125     for (i = 0; i < iDialogs.Count(); i++)
       
   126         {
       
   127         iDialogs[i]->ConnectionDeleted();
       
   128         }
       
   129     iDialogs.Reset();
       
   130 
       
   131     for (i = 0; i < iTransactions.Count(); i++)
       
   132         {
       
   133         iTransactions[i]->Detach(*this);
       
   134         }
       
   135     iTransactions.Reset();
       
   136 
       
   137     for (i = 0; i < iRefreshes.Count(); i++)
       
   138         {
       
   139         iRefreshes[i]->RemoveRefreshOwner(*this);
       
   140         }    
       
   141     iRefreshes.Reset();
       
   142 
       
   143     delete iClientConnection;    
       
   144     delete iCallbackInfo;
       
   145 	}
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CSIPConnectionImplementation::State
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 CSIPConnection::TState CSIPConnectionImplementation::State() const
       
   152     {
       
   153     __TEST_INVARIANT;
       
   154     return iClientConnection->State();
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CSIPConnectionImplementation::SendRequestL
       
   159 // No need to check connection state. It is checked in SIPClient.
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 CSIPClientTransaction*
       
   163 CSIPConnectionImplementation::SendRequestL(CSIPRequestElements* aElements,
       
   164 			                               TUint32* aRegistrationId,
       
   165 										   CSIPRefresh* aRefresh)
       
   166     {
       
   167     __TEST_INVARIANT;
       
   168     __ASSERT_ALWAYS(aElements &&
       
   169     	(aRegistrationId || (aElements->FromHeader() != NULL)),
       
   170     	User::Leave(KErrArgument));
       
   171 	RStringF method = aElements->Method();
       
   172 	__ASSERT_ALWAYS(method != SIPStrings::StringF(SipStrConsts::ERegister) &&
       
   173 					method != SIPStrings::StringF(SipStrConsts::EInvite) &&
       
   174 					method != SIPStrings::StringF(SipStrConsts::EPrack) &&
       
   175 					method != SIPStrings::StringF(SipStrConsts::EAck) &&
       
   176 					method != SIPStrings::StringF(SipStrConsts::ECancel) &&
       
   177 					method != SIPStrings::StringF(SipStrConsts::EUpdate) &&
       
   178 					method != SIPStrings::StringF(SipStrConsts::EBye) &&
       
   179 					method != SIPStrings::StringF(SipStrConsts::ESubscribe) &&
       
   180 					method != SIPStrings::StringF(SipStrConsts::ERefer) &&
       
   181 					method != SIPStrings::StringF(SipStrConsts::ENotify),
       
   182 					User::Leave(KErrArgument));
       
   183     CSIPClientTransaction* ta =
       
   184     	CSIPClientTransaction::NewLC(method, *this, aRefresh);
       
   185     TUint32 requestId(0);
       
   186     iClientConnection->SendRequestL(*aElements,
       
   187                                     requestId,
       
   188                                     aRegistrationId ? *aRegistrationId : 0,
       
   189                                     (aRefresh != NULL));
       
   190     if (aRefresh)
       
   191         {
       
   192         iRefreshes.AppendL(aRefresh);
       
   193         aRefresh->SetRequestType(method);
       
   194         aRefresh->SetRefreshOwner(*this);
       
   195         }
       
   196     CleanupStack::Pop(ta);
       
   197     ta->SetRequestId(requestId);
       
   198     delete aElements;
       
   199 
       
   200     __TEST_INVARIANT;
       
   201     return ta;
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CSIPConnectionImplementation::FetchRegistrationsL
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 CSIPClientTransaction* CSIPConnectionImplementation::FetchRegistrationsL(
       
   209 											CSIPRequestElements* aElements)
       
   210     {
       
   211     __TEST_INVARIANT;
       
   212 
       
   213 	CSIPClientTransaction* ta = CSIPClientTransaction::NewL(
       
   214     							SIPStrings::StringF(SipStrConsts::ERegister),
       
   215                                 *this);
       
   216 	CleanupStack::PushL(ta);
       
   217 	TUint32 requestId(0);
       
   218     iClientConnection->FetchRegistrationsL(*aElements, requestId);
       
   219     CleanupStack::Pop(ta);
       
   220 	ta->SetRequestId(requestId);
       
   221     delete aElements;
       
   222 
       
   223     __TEST_INVARIANT;
       
   224     return ta;
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CSIPConnectionImplementation::IncomingRequestL
       
   229 // Invariant mustn't be used after callback, as observer may delete this object
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void
       
   233 CSIPConnectionImplementation::IncomingRequestL(CSIPRequestElements* aElements,
       
   234 	                                           TUint32 aRequestId)									
       
   235     {
       
   236     __TEST_INVARIANT;
       
   237      __SIP_ASSERT_LEAVE(aElements, KErrArgument);
       
   238 
       
   239     iObserver.IncomingRequest(
       
   240     	CSIPServerTransaction::NewL(aRequestId, *this, aElements));
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CSIPConnectionImplementation::IncomingDialogRequestL
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void CSIPConnectionImplementation::IncomingDialogRequestL(
       
   248 											CSIPRequestElements* aElements,
       
   249 		                                    TUint32 aRequestId,
       
   250 								            TUint32 aDialogId)
       
   251     {
       
   252     __TEST_INVARIANT;
       
   253     __SIP_ASSERT_LEAVE(aElements, KErrArgument);
       
   254 
       
   255 	CSIPDialogImplementation* dialog = FindDialog(aDialogId);
       
   256     if (dialog)
       
   257         {
       
   258 	    CSIPServerTransaction* ta =
       
   259     		CSIPServerTransaction::NewLC(aRequestId, *this, aElements);
       
   260     	CleanupStack::PushL(TCleanupItem(
       
   261         	CSIPServerTransaction::DetachRequestElements, ta));
       
   262 
       
   263         TBool useCallback = dialog->IncomingRequestL(ta, *iCallbackInfo);
       
   264 		CleanupStack::Pop(2); //TCleanupItem, ta
       
   265 
       
   266         if (useCallback)
       
   267             {         
       
   268             iCallbackInfo->ExecuteCallback(iObserver);            
       
   269             }
       
   270         }
       
   271     else
       
   272         {
       
   273         delete aElements;
       
   274         }    
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CSIPConnectionImplementation::IncomingResponseL
       
   279 // An error response to REGISTER comes without registerId.
       
   280 // This response is not related to any existing refresh or dialog.
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CSIPConnectionImplementation::IncomingResponseL(
       
   284 											CSIPResponseElements* aElements,
       
   285                                        		TUint32 aRequestId)
       
   286     {
       
   287     __TEST_INVARIANT;
       
   288     __SIP_ASSERT_LEAVE(aElements != NULL, KErrArgument);
       
   289 
       
   290     CSIPTransactionBase* ta = FindTransaction(aRequestId);
       
   291     if (ta)
       
   292         {
       
   293         __SIP_ASSERT_LEAVE(ta->IsSIPClientTransaction(), KErrArgument);
       
   294 
       
   295         CSIPClientTransaction* clientTa =
       
   296             static_cast<CSIPClientTransaction*>(ta);        
       
   297         clientTa->SetResponseElements(aElements);        
       
   298 
       
   299         iObserver.IncomingResponse(*clientTa);
       
   300         }
       
   301     else
       
   302         {        
       
   303         CRegBindingImplementation* reg = FindRegistration(aRequestId);
       
   304         if (reg)
       
   305             {
       
   306             if (reg->IncomingResponseL(aElements,
       
   307 		                               aRequestId,
       
   308                                        0 /* empty registration id */,
       
   309                                        0 /* empty refresh id */,
       
   310 					                   *iCallbackInfo))
       
   311                 {
       
   312                 iCallbackInfo->ExecuteCallback(iObserver);
       
   313                 }
       
   314             }
       
   315         else
       
   316             {
       
   317             delete aElements;
       
   318             }
       
   319         }
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CSIPConnectionImplementation::IncomingRegistrationResponseL
       
   324 // Response to an existing refreshed registration, or a response creating a
       
   325 // refreshed registration.
       
   326 // If the response to the initial REGISTER is an error response, it comes in
       
   327 // IncomingResponseL or IncomingRefreshResponseL.
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 void CSIPConnectionImplementation::IncomingRegistrationResponseL(
       
   331 											CSIPResponseElements* aElements,
       
   332 											TUint32 aRequestId,
       
   333 		                                    TUint32 aRefreshId,
       
   334 								            TUint32 aRegistrationId)
       
   335     {
       
   336     __TEST_INVARIANT;
       
   337     __SIP_ASSERT_LEAVE(aElements != NULL, KErrArgument);
       
   338 
       
   339 	CRegBindingImplementation* reg = FindRegistration(aRegistrationId,
       
   340 													  aRequestId);
       
   341     if (reg)
       
   342         {
       
   343         if (reg->IncomingResponseL(aElements,
       
   344 		                           aRequestId,
       
   345                                    aRegistrationId,
       
   346                                    aRefreshId,
       
   347                                    *iCallbackInfo))
       
   348             {
       
   349             iCallbackInfo->ExecuteCallback(iObserver);            
       
   350             }
       
   351         }
       
   352     else
       
   353         {
       
   354         delete aElements;
       
   355         }
       
   356     }
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // CSIPConnectionImplementation::IncomingRefreshResponseL
       
   360 // Response creating a refresh or an error response to an existing refresh.
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 void CSIPConnectionImplementation::IncomingRefreshResponseL(
       
   364 											CSIPResponseElements* aElements,
       
   365 		                               		TUint32 aRequestId,
       
   366 							           		TUint32 aRefreshId)
       
   367     {
       
   368     __TEST_INVARIANT;
       
   369     __SIP_ASSERT_LEAVE(aElements != NULL, KErrArgument);
       
   370 
       
   371     CSIPRefresh* refresh = NULL;
       
   372     CSIPClientTransaction* ta = NULL;
       
   373     if (FindRefresh(aRequestId, aRefreshId, &refresh, &ta))
       
   374         {
       
   375 		refresh->SetRefreshIdIfEmpty(aRefreshId);
       
   376 	    refresh->UpdateRefreshState(aElements->StatusCode());
       
   377 
       
   378 		TUint statusCode = aElements->StatusCode();
       
   379 		if (ta)
       
   380 			{
       
   381 	       	ta->SetResponseElements(aElements);
       
   382 	       	aElements = NULL; // Ownership of aElements was passed
       
   383 			}
       
   384 		if (statusCode >= 300)
       
   385 			{
       
   386         	iObserver.ErrorOccured(KErrSIPTerminatedWithResponse, *refresh);
       
   387 			}
       
   388 		else
       
   389 			{
       
   390 			// Ignore the response if application has deleted the transaction
       
   391 	        if (ta)
       
   392 	            {
       
   393 	        	iObserver.IncomingResponse(*ta);
       
   394 	            }
       
   395 			}
       
   396         }
       
   397     else
       
   398     	{
       
   399     	CRegBindingImplementation* reg = FindRegistration(aRequestId);
       
   400         if (reg)
       
   401             {
       
   402             if (reg->IncomingResponseL(aElements,
       
   403 		                               aRequestId,
       
   404                                        0 /* empty registration id */,
       
   405                                        aRefreshId,
       
   406 					                   *iCallbackInfo))
       
   407                 {
       
   408                 iCallbackInfo->ExecuteCallback(iObserver);
       
   409                 }
       
   410             aElements = NULL; // Ownership of aElements was passed
       
   411             }
       
   412     	}
       
   413 
       
   414     delete aElements;
       
   415     }
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // CSIPConnectionImplementation::ErrorOccured
       
   419 // If the initial REGISTER failed, the error is related to a requestId of a
       
   420 // registration transaction. RegisterId is received together with 2xx.
       
   421 // -----------------------------------------------------------------------------
       
   422 //
       
   423 void CSIPConnectionImplementation::ErrorOccured(TInt aError, TUint32 aRequestId)
       
   424     {
       
   425     __TEST_INVARIANT;
       
   426 
       
   427 	CRegBindingImplementation* reg = FindRegistration(aRequestId);
       
   428     if (reg)
       
   429         {
       
   430         if (reg->ErrorOccured(aError, aRequestId, *iCallbackInfo))
       
   431             {
       
   432             iCallbackInfo->ExecuteCallback(iObserver);            
       
   433             }
       
   434         }
       
   435     else
       
   436         {
       
   437         CSIPTransactionBase* ta = FindTransaction(aRequestId);
       
   438         if (ta)
       
   439             {
       
   440             ta->ChangeState(CSIPTransactionBase::ETerminated);
       
   441 
       
   442             if (aError == KInviteTransactionCancelled)
       
   443             	{
       
   444             	__SIP_ASSERT_RETURN(!ta->IsSIPClientTransaction(),
       
   445             						KErrArgument);
       
   446             	iObserver.InviteCanceled(
       
   447             		static_cast<CSIPServerTransaction&>(*ta));
       
   448             	}
       
   449             else
       
   450             	{
       
   451             	iObserver.ErrorOccured(aError, *ta);
       
   452             	}
       
   453             }
       
   454         else
       
   455             {
       
   456             CSIPDialogImplementation* dialog = 
       
   457                 FindDialogByRequestId(aRequestId);
       
   458             if (dialog &&
       
   459                 dialog->ErrorOccured(aError, aRequestId, *iCallbackInfo))
       
   460                 {
       
   461                 iCallbackInfo->ExecuteCallback(iObserver);
       
   462                 }
       
   463             }
       
   464         }
       
   465     }
       
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 // CSIPConnectionImplementation::RefreshErrorOccured
       
   469 // Error to a standalone refresh request, not to registration or dialog refresh.
       
   470 // -----------------------------------------------------------------------------
       
   471 //
       
   472 void CSIPConnectionImplementation::RefreshErrorOccured(TInt aError,
       
   473 													   TUint32 aRefreshId)
       
   474     {
       
   475     __TEST_INVARIANT;
       
   476 
       
   477     TUint32 dummyRequestId(0);
       
   478     CSIPRefresh* refresh = NULL;
       
   479     CSIPClientTransaction* ta = NULL;
       
   480     if (FindRefresh(dummyRequestId, aRefreshId, &refresh, &ta))
       
   481         {
       
   482         if (ta)
       
   483             {
       
   484             ta->ChangeState(CSIPTransactionBase::ETerminated);
       
   485             }
       
   486         refresh->ChangeState(CSIPRefresh::ETerminated);
       
   487 
       
   488         iObserver.ErrorOccured(aError, *refresh);
       
   489         }
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // CSIPConnectionImplementation::RegistrationErrorOccured
       
   494 // -----------------------------------------------------------------------------
       
   495 //
       
   496 void
       
   497 CSIPConnectionImplementation::RegistrationErrorOccured(TInt aError,
       
   498                                   			  		   TUint32 aRegistrationId,
       
   499                                   			  		   TUint32 aRequestId)
       
   500     {
       
   501     __TEST_INVARIANT;
       
   502 
       
   503  	CRegBindingImplementation* reg = FindRegistration(aRegistrationId,
       
   504  													  aRequestId);
       
   505     if (reg && reg->ErrorOccured(aError, aRequestId, *iCallbackInfo))
       
   506         {
       
   507         iCallbackInfo->ExecuteCallback(iObserver);
       
   508         }
       
   509     }
       
   510 
       
   511 // -----------------------------------------------------------------------------
       
   512 // CSIPConnectionImplementation::DialogErrorOccured
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 void CSIPConnectionImplementation::DialogErrorOccured(TInt aError,
       
   516                                   					  TUint32 aDialogId,
       
   517                                   					  TUint32 aRequestId)
       
   518     {
       
   519     __TEST_INVARIANT;
       
   520 
       
   521     CSIPDialogImplementation* dialog = FindDialog(aDialogId);            
       
   522     if (dialog && dialog->ErrorOccured(aError, aRequestId, *iCallbackInfo))
       
   523         {
       
   524         iCallbackInfo->ExecuteCallback(iObserver);
       
   525         }
       
   526     }
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // CSIPConnectionImplementation::DialogErrorOccured
       
   530 // -----------------------------------------------------------------------------
       
   531 //
       
   532 void CSIPConnectionImplementation::DialogErrorOccured(TInt aError,
       
   533                                   	 				  TUint32 aDialogId,
       
   534                                   					  TUint32 aRefreshId,
       
   535                                   					  TUint32 aRequestId)
       
   536     {
       
   537     __TEST_INVARIANT;
       
   538 
       
   539     CSIPDialogImplementation* dialog = FindDialog(aDialogId);    
       
   540     if (dialog &&        
       
   541         dialog->ErrorOccured(aError, aRefreshId, aRequestId, *iCallbackInfo))
       
   542         {
       
   543         iCallbackInfo->ExecuteCallback(iObserver);
       
   544         }
       
   545     }
       
   546 
       
   547 // -----------------------------------------------------------------------------
       
   548 // CSIPConnectionImplementation::ConnectionStateChanged
       
   549 // -----------------------------------------------------------------------------
       
   550 //
       
   551 void CSIPConnectionImplementation::ConnectionStateChanged(
       
   552 											CSIPConnection::TState aState)
       
   553     {
       
   554     __TEST_INVARIANT;
       
   555 
       
   556     if (aState == CSIPConnection::EInactive ||
       
   557     	aState == CSIPConnection::EUnavailable)
       
   558         {
       
   559         ConnectionLost();
       
   560         }
       
   561 
       
   562     iObserver.ConnectionStateChanged(aState);
       
   563     }
       
   564 
       
   565 // -----------------------------------------------------------------------------
       
   566 // CSIPConnectionImplementation::ConnectionLost
       
   567 // -----------------------------------------------------------------------------
       
   568 //
       
   569 void CSIPConnectionImplementation::ConnectionLost() const
       
   570     {
       
   571     __TEST_INVARIANT;
       
   572 
       
   573     TInt i = 0;
       
   574     for (i = 0; i < iRegistrations.Count(); i++)
       
   575         {
       
   576         iRegistrations[i]->ConnectionLost();
       
   577         }
       
   578 
       
   579     for (i = 0; i < iDialogs.Count(); i++)
       
   580         {
       
   581         iDialogs[i]->ConnectionLost();
       
   582         }
       
   583 
       
   584     for (i = 0; i < iRefreshes.Count(); i++)
       
   585         {
       
   586         iRefreshes[i]->ChangeState(CSIPRefresh::ETerminated);
       
   587         }
       
   588 
       
   589     for (i = 0; i < iTransactions.Count(); i++)
       
   590         {        
       
   591         iTransactions[i]->ChangeState(CSIPTransactionBase::ETerminated);
       
   592         }    
       
   593     }
       
   594 
       
   595 // -----------------------------------------------------------------------------
       
   596 // CSIPConnectionImplementation::InviteCompleted
       
   597 // -----------------------------------------------------------------------------
       
   598 //
       
   599 void CSIPConnectionImplementation::InviteCompleted(TUint32 aRequestId)
       
   600     {
       
   601     __TEST_INVARIANT;
       
   602 
       
   603     CSIPDialogImplementation* dialog = FindDialogByRequestId(aRequestId);
       
   604     if (dialog)
       
   605         {
       
   606         CSIPClientTransaction* ta = static_cast<CSIPClientTransaction*>
       
   607             (dialog->FindTransaction(aRequestId));
       
   608         __SIP_ASSERT_RETURN(ta, KErrNotFound);
       
   609 
       
   610         ta->ChangeState(CSIPTransactionBase::ETerminated);
       
   611         iObserver.InviteCompleted(*ta);
       
   612         }
       
   613     }
       
   614 
       
   615 // -----------------------------------------------------------------------------
       
   616 // CSIPConnectionImplementation::IapId
       
   617 // -----------------------------------------------------------------------------
       
   618 //
       
   619 TUint32 CSIPConnectionImplementation::IapId() const
       
   620     {
       
   621     __TEST_INVARIANT;
       
   622     return iIapId;
       
   623     }
       
   624 
       
   625 // -----------------------------------------------------------------------------
       
   626 // CSIPConnectionImplementation::SIP
       
   627 // -----------------------------------------------------------------------------
       
   628 //
       
   629 CSIP* CSIPConnectionImplementation::SIP()
       
   630 	{
       
   631 	__TEST_INVARIANT;
       
   632 	return iSIP;
       
   633 	}
       
   634  
       
   635 // -----------------------------------------------------------------------------
       
   636 // CSIPConnectionImplementation::SIP
       
   637 // -----------------------------------------------------------------------------
       
   638 //      
       
   639 const CSIP* CSIPConnectionImplementation::SIP() const
       
   640 	{
       
   641 	__TEST_INVARIANT;
       
   642 	return iSIP;
       
   643 	}
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // CSIPConnectionImplementation::SetOptL
       
   647 // -----------------------------------------------------------------------------
       
   648 //
       
   649 void CSIPConnectionImplementation::SetOptL(TUint aOptionName,
       
   650 				                      	   TUint aOptionLevel,
       
   651 				                      	   const TDesC8& aOption)
       
   652 	{
       
   653 	__TEST_INVARIANT;
       
   654 	return iClientConnection->SetOptL(aOptionName, aOptionLevel, aOption);
       
   655 	}
       
   656 
       
   657 // -----------------------------------------------------------------------------
       
   658 // CSIPConnectionImplementation::SetOptL
       
   659 // -----------------------------------------------------------------------------
       
   660 //
       
   661 void CSIPConnectionImplementation::SetOptL(TUint aOptionName,
       
   662 			                          	   TUint aOptionLevel,
       
   663 			                          	   TInt aOption)
       
   664 	{
       
   665 	__TEST_INVARIANT;
       
   666 	return iClientConnection->SetOptL(aOptionName, aOptionLevel, aOption);
       
   667 	}
       
   668 
       
   669 // -----------------------------------------------------------------------------
       
   670 // CSIPConnectionImplementation::AddRegistrationL
       
   671 // -----------------------------------------------------------------------------
       
   672 //
       
   673 void CSIPConnectionImplementation::AddRegistrationL(
       
   674 									CRegBindingImplementation& aRegistration)									
       
   675     {
       
   676     __TEST_INVARIANT;
       
   677     iRegistrations.AppendL(&aRegistration);
       
   678     }
       
   679 
       
   680 // -----------------------------------------------------------------------------
       
   681 // CSIPConnectionImplementation::RemoveRegistration
       
   682 // -----------------------------------------------------------------------------
       
   683 //
       
   684 void CSIPConnectionImplementation::RemoveRegistration(
       
   685 							const CRegBindingImplementation& aRegistration)						
       
   686     {
       
   687     __TEST_INVARIANT;
       
   688 
       
   689     TInt pos = iRegistrations.Find(&aRegistration);
       
   690     if (pos != KErrNotFound)
       
   691         {
       
   692         iRegistrations.Remove(pos);
       
   693         }
       
   694 
       
   695     __TEST_INVARIANT;
       
   696     }
       
   697 
       
   698 // -----------------------------------------------------------------------------
       
   699 // CSIPConnectionImplementation::AddDialog
       
   700 // -----------------------------------------------------------------------------
       
   701 //
       
   702 void CSIPConnectionImplementation::AddDialogL(CSIPDialogImplementation& aDialog)
       
   703     {
       
   704     __TEST_INVARIANT;
       
   705     iDialogs.AppendL(&aDialog);
       
   706     }
       
   707 
       
   708 // -----------------------------------------------------------------------------
       
   709 // CSIPConnectionImplementation::RemoveDialog
       
   710 // -----------------------------------------------------------------------------
       
   711 //
       
   712 void CSIPConnectionImplementation::RemoveDialog(
       
   713 									const CSIPDialogImplementation& aDialog)
       
   714     {
       
   715     __TEST_INVARIANT;
       
   716 
       
   717 	iClientConnection->TerminateDialog(aDialog.DialogId());
       
   718 
       
   719     TInt pos = iDialogs.Find(&aDialog);
       
   720     if (pos != KErrNotFound)
       
   721         {
       
   722         iDialogs.Remove(pos);
       
   723         }
       
   724 
       
   725     __TEST_INVARIANT;
       
   726     }
       
   727 
       
   728 // -----------------------------------------------------------------------------
       
   729 // CSIPConnectionImplementation::FindTransaction
       
   730 // -----------------------------------------------------------------------------
       
   731 //
       
   732 CSIPTransactionBase* CSIPConnectionImplementation::FindTransaction(
       
   733     TUint32 aRequestId) const
       
   734     {
       
   735     __TEST_INVARIANT;
       
   736 
       
   737     for (TInt i = 0; i < iTransactions.Count(); i++)
       
   738         {
       
   739         if (iTransactions[i]->RequestId() == aRequestId)
       
   740             {
       
   741             return iTransactions[i];
       
   742             }   
       
   743         }
       
   744     
       
   745     return NULL;
       
   746     }
       
   747 
       
   748 // -----------------------------------------------------------------------------
       
   749 // CSIPConnectionImplementation::FindClientTransaction
       
   750 // -----------------------------------------------------------------------------
       
   751 //
       
   752 CSIPClientTransaction* CSIPConnectionImplementation::FindClientTransaction(
       
   753     TUint32 aRequestId) const
       
   754     {
       
   755     __TEST_INVARIANT;
       
   756     
       
   757     CSIPTransactionBase* ta = FindTransaction(aRequestId);
       
   758     if (ta && ta->IsSIPClientTransaction())
       
   759         {
       
   760         return static_cast<CSIPClientTransaction*>(ta);
       
   761         }
       
   762     
       
   763     CRegBindingImplementation* registration = FindRegistration(aRequestId);
       
   764     if (registration)
       
   765         {
       
   766         return registration->FindTransaction(aRequestId);
       
   767         }
       
   768     
       
   769     CSIPDialogImplementation* dialog = FindDialogByRequestId(aRequestId);
       
   770     if (dialog)
       
   771         {
       
   772         ta = dialog->FindTransaction(aRequestId);
       
   773         if (ta && ta->IsSIPClientTransaction())
       
   774             {
       
   775             return static_cast<CSIPClientTransaction*>(ta);
       
   776             }
       
   777         }
       
   778     
       
   779     return NULL;
       
   780     }
       
   781 
       
   782 // -----------------------------------------------------------------------------
       
   783 // CSIPConnectionImplementation::FindRefresh
       
   784 // -----------------------------------------------------------------------------
       
   785 //
       
   786 CSIPRefresh* CSIPConnectionImplementation::FindRefresh(
       
   787     TUint32 aRequestId,
       
   788     TUint32 aRefreshId) const
       
   789     {
       
   790     CSIPRefresh* refresh = NULL;
       
   791     
       
   792     CSIPClientTransaction* dummyTa = NULL;
       
   793     if (FindRefresh(aRequestId,aRefreshId,&refresh,&dummyTa))
       
   794         {
       
   795         return refresh;
       
   796         }
       
   797         
       
   798     for (TInt i = 0; i < iDialogs.Count(); i++)
       
   799         {
       
   800         refresh = iDialogs[i]->FindRefresh(aRequestId,aRefreshId);
       
   801         }
       
   802  
       
   803     for (TInt i = 0; !refresh && i < iRegistrations.Count(); i++)
       
   804         {
       
   805         CSIPRefresh* regRefresh = iRegistrations[i]->SIPRefresh();
       
   806         if (regRefresh)
       
   807            {
       
   808             if((regRefresh->RefreshId() == aRefreshId) ||
       
   809                (regRefresh->SIPTransaction() && 
       
   810                regRefresh->SIPTransaction()->RequestId() == aRequestId))
       
   811               {
       
   812                refresh = regRefresh;
       
   813               }
       
   814            }
       
   815         }
       
   816         
       
   817     return refresh;
       
   818     }    
       
   819 
       
   820 // -----------------------------------------------------------------------------
       
   821 // CSIPConnectionImplementation::FindRefresh
       
   822 // -----------------------------------------------------------------------------
       
   823 //
       
   824 TBool CSIPConnectionImplementation::FindRefresh(TUint32 aRequestId,
       
   825 	TUint32 aRefreshId,
       
   826 	CSIPRefresh** aRefresh,
       
   827 	CSIPClientTransaction** aTransaction) const
       
   828     {
       
   829     __TEST_INVARIANT;
       
   830 
       
   831     for (TInt i = 0; i < iRefreshes.Count(); i++)
       
   832         {
       
   833         if (iRefreshes[i]->DoesMatch(aRefreshId))
       
   834             {
       
   835             *aRefresh = iRefreshes[i];
       
   836             //Transaction can be NULL
       
   837             *aTransaction = iRefreshes[i]->Transaction();
       
   838             return ETrue;
       
   839             }
       
   840         }
       
   841 
       
   842     CSIPTransactionBase* ta = FindTransaction(aRequestId);
       
   843     if (ta && ta->IsSIPClientTransaction())
       
   844         {
       
   845         CSIPClientTransaction* clientTa =
       
   846             static_cast<CSIPClientTransaction*>(ta);
       
   847 
       
   848         //Application may've deleted the refresh, even if transaction is found
       
   849         if (clientTa->Refresh())
       
   850             {
       
   851             *aTransaction = clientTa;
       
   852             *aRefresh = clientTa->Refresh();
       
   853             return ETrue;
       
   854             }
       
   855         }
       
   856 
       
   857     return EFalse;
       
   858     }
       
   859 
       
   860 // -----------------------------------------------------------------------------
       
   861 // CSIPConnectionImplementation::FindRegistration
       
   862 // First search by aRegistrationId. If not found, the RegistrationId hasn't yet
       
   863 // been received from SIP client. Search again with aRequestId.
       
   864 // -----------------------------------------------------------------------------
       
   865 //
       
   866 CRegBindingImplementation*
       
   867 CSIPConnectionImplementation::FindRegistration(TUint32 aRegistrationId,
       
   868                                  			   TUint32 aRequestId) const
       
   869     {
       
   870     __TEST_INVARIANT;
       
   871 
       
   872     for (TInt i = 0; i < iRegistrations.Count(); i++)
       
   873         {
       
   874         if (iRegistrations[i]->ContextId() == aRegistrationId)
       
   875             {        
       
   876             return iRegistrations[i];
       
   877             }
       
   878         }
       
   879 
       
   880     return FindRegistration(aRequestId);
       
   881     }
       
   882 
       
   883 // -----------------------------------------------------------------------------
       
   884 // CSIPConnectionImplementation::FindRegistration
       
   885 // -----------------------------------------------------------------------------
       
   886 //
       
   887 CRegBindingImplementation*
       
   888 CSIPConnectionImplementation::FindRegistration(TUint32 aRequestId) const
       
   889     {
       
   890     __TEST_INVARIANT;
       
   891 
       
   892     for (TInt i = 0; i < iRegistrations.Count(); i++)
       
   893         {
       
   894         if (iRegistrations[i]->FindTransaction(aRequestId))
       
   895             {
       
   896             return iRegistrations[i];
       
   897             }
       
   898         }
       
   899 
       
   900     return NULL;
       
   901     }
       
   902 
       
   903 // -----------------------------------------------------------------------------
       
   904 // CSIPConnectionImplementation::FindDialog
       
   905 // -----------------------------------------------------------------------------
       
   906 //
       
   907 CSIPDialogImplementation*
       
   908 CSIPConnectionImplementation::FindDialog(TUint32 aDialogId) const
       
   909     {
       
   910     __TEST_INVARIANT;
       
   911 
       
   912     for (TInt i = 0; i < iDialogs.Count(); i++)
       
   913         {
       
   914         if (iDialogs[i]->DialogId() == aDialogId)
       
   915             {        
       
   916             return iDialogs[i];
       
   917             }   
       
   918         }
       
   919 
       
   920     return NULL;
       
   921     }
       
   922 
       
   923 // -----------------------------------------------------------------------------
       
   924 // CSIPConnectionImplementation::FindDialogByRequestId
       
   925 // -----------------------------------------------------------------------------
       
   926 //
       
   927 CSIPDialogImplementation*
       
   928 CSIPConnectionImplementation::FindDialogByRequestId(TUint32 aRequestId) const
       
   929     {
       
   930     __TEST_INVARIANT;
       
   931 
       
   932     for (TInt i = 0; i < iDialogs.Count(); i++)
       
   933         {
       
   934         if (iDialogs[i]->FindTransaction(aRequestId))
       
   935             {        
       
   936             return iDialogs[i];
       
   937             }   
       
   938         }
       
   939 
       
   940     return NULL;
       
   941     }
       
   942 
       
   943 // -----------------------------------------------------------------------------
       
   944 // CSIPConnectionImplementation::InitialRegisterStateL
       
   945 // -----------------------------------------------------------------------------
       
   946 //
       
   947 CRegistrationState* CSIPConnectionImplementation::InitialRegisterStateL() const
       
   948     {
       
   949     __TEST_INVARIANT;
       
   950     CheckCSipL();
       
   951 
       
   952     return iSIP->Implementation().InitialRegisterState();
       
   953     }
       
   954 
       
   955 // -----------------------------------------------------------------------------
       
   956 // CSIPConnectionImplementation::InitialDialogStateL
       
   957 // -----------------------------------------------------------------------------
       
   958 //
       
   959 CDialogState* CSIPConnectionImplementation::InitialDialogStateL() const
       
   960     {
       
   961     __TEST_INVARIANT;
       
   962     CheckCSipL();
       
   963 
       
   964     return iSIP->Implementation().InitialDialogState();
       
   965     }
       
   966 
       
   967 // -----------------------------------------------------------------------------
       
   968 // CSIPConnectionImplementation::CSIPDeleted
       
   969 // Inform registrations and dialogs, as CSIP deletes their state handlers.
       
   970 // -----------------------------------------------------------------------------
       
   971 //
       
   972 void CSIPConnectionImplementation::CSIPDeleted()
       
   973     {
       
   974     __TEST_INVARIANT;
       
   975 
       
   976     iSIP = NULL;
       
   977      
       
   978     TInt i = 0;
       
   979     for (i = 0; i < iRegistrations.Count(); i++)
       
   980         {
       
   981         iRegistrations[i]->ChangeState(NULL);
       
   982         }
       
   983     
       
   984     for (i = 0; i < iDialogs.Count(); i++)
       
   985         {
       
   986         iDialogs[i]->ChangeState(NULL);        
       
   987         }
       
   988 
       
   989     __TEST_INVARIANT;
       
   990     }
       
   991 
       
   992 // -----------------------------------------------------------------------------
       
   993 // CSIPConnectionImplementation::CheckCSipL
       
   994 // Don't call invariant as CheckCSipL is also used by ConstructL.
       
   995 // -----------------------------------------------------------------------------
       
   996 //
       
   997 void CSIPConnectionImplementation::CheckCSipL() const
       
   998     {
       
   999     __ASSERT_ALWAYS(iSIP, User::Leave(KErrSIPResourceNotAvailable));
       
  1000     }
       
  1001 
       
  1002 // -----------------------------------------------------------------------------
       
  1003 // CSIPConnectionImplementation::ClientConnectionL
       
  1004 // -----------------------------------------------------------------------------
       
  1005 //
       
  1006 CSIPClientConnection& CSIPConnectionImplementation::ClientConnectionL()
       
  1007     {
       
  1008     __TEST_INVARIANT;
       
  1009     return *iClientConnection;
       
  1010     }
       
  1011 
       
  1012 // -----------------------------------------------------------------------------
       
  1013 // CSIPConnectionImplementation::ClientConnection
       
  1014 // -----------------------------------------------------------------------------
       
  1015 //
       
  1016 CSIPClientConnection* CSIPConnectionImplementation::ClientConnection()
       
  1017 	{
       
  1018 	__TEST_INVARIANT;
       
  1019 	return iClientConnection;
       
  1020 	}
       
  1021 
       
  1022 // -----------------------------------------------------------------------------
       
  1023 // CSIPConnectionImplementation::SIPConnectionL
       
  1024 // -----------------------------------------------------------------------------
       
  1025 //
       
  1026 CSIPConnection& CSIPConnectionImplementation::SIPConnectionL()
       
  1027     {
       
  1028     __TEST_INVARIANT;    
       
  1029     return iConnection;
       
  1030     }
       
  1031 
       
  1032 // -----------------------------------------------------------------------------
       
  1033 // CSIPConnectionImplementation::UpdateRefreshL
       
  1034 // No need to check connection state. It is checked in SIPClient.
       
  1035 // -----------------------------------------------------------------------------
       
  1036 //
       
  1037 CSIPClientTransaction*
       
  1038 CSIPConnectionImplementation::UpdateRefreshL(CSIPRefresh& aRefresh,
       
  1039                                				 CSIPMessageElements* aElements,
       
  1040                                				 TBool aTerminate)
       
  1041     {
       
  1042     __TEST_INVARIANT;
       
  1043     __ASSERT_ALWAYS(iRefreshes.Find(&aRefresh) != KErrNotFound,
       
  1044                     User::Leave(KErrNotFound));   
       
  1045 
       
  1046 	CSIPClientTransaction* ta =
       
  1047         CSIPClientTransaction::NewLC(aRefresh.RequestType(),                                    
       
  1048                                      *this,
       
  1049                                      &aRefresh);
       
  1050     TUint32 requestId(0);
       
  1051     if (aTerminate)
       
  1052     	{
       
  1053     	iClientConnection->SendRequestAndTerminateRefreshL(aRefresh.RefreshId(),
       
  1054 	                                                       requestId,
       
  1055 	                                                       aElements);
       
  1056     	}
       
  1057     else
       
  1058     	{
       
  1059     	iClientConnection->SendRequestAndUpdateRefreshL(aRefresh.RefreshId(),
       
  1060                                                     	requestId,
       
  1061                                                     	aElements);
       
  1062     	}
       
  1063 	CleanupStack::Pop(ta);
       
  1064 	ta->SetRequestId(requestId);
       
  1065     delete aElements;
       
  1066 
       
  1067     __TEST_INVARIANT;
       
  1068     return ta;
       
  1069     }
       
  1070 
       
  1071 // -----------------------------------------------------------------------------
       
  1072 // CSIPConnectionImplementation::DeletingRefresh
       
  1073 // -----------------------------------------------------------------------------
       
  1074 //
       
  1075 void CSIPConnectionImplementation::DeletingRefresh(CSIPRefresh& aRefresh,
       
  1076 												   TUint32 aRefreshId)
       
  1077     {
       
  1078     __TEST_INVARIANT;
       
  1079 
       
  1080     TInt pos = iRefreshes.Find(&aRefresh);
       
  1081     if (pos != KErrNotFound)
       
  1082         {
       
  1083         iRefreshes.Remove(pos);
       
  1084         }
       
  1085 
       
  1086     iClientConnection->TerminateRefresh(aRefreshId);
       
  1087 
       
  1088     __TEST_INVARIANT;
       
  1089     }
       
  1090 
       
  1091 // -----------------------------------------------------------------------------
       
  1092 // CSIPConnectionImplementation::TransactionAssociation
       
  1093 // -----------------------------------------------------------------------------
       
  1094 //
       
  1095 MTransactionAssociation& CSIPConnectionImplementation::TransactionAssociation()
       
  1096 	{
       
  1097 	__TEST_INVARIANT;
       
  1098 	return *this;
       
  1099 	}
       
  1100 
       
  1101 // -----------------------------------------------------------------------------
       
  1102 // CSIPConnectionImplementation::CheckIfStandAlone
       
  1103 // -----------------------------------------------------------------------------
       
  1104 //
       
  1105 TInt CSIPConnectionImplementation::CheckIfStandAlone()
       
  1106 	{
       
  1107 	__TEST_INVARIANT;
       
  1108 	return KErrNone;
       
  1109 	}
       
  1110 
       
  1111 // -----------------------------------------------------------------------------
       
  1112 // CSIPConnectionImplementation::AddTransactionL
       
  1113 // -----------------------------------------------------------------------------
       
  1114 //
       
  1115 void
       
  1116 CSIPConnectionImplementation::AddTransactionL(CSIPTransactionBase& aTransaction)
       
  1117     {
       
  1118     __TEST_INVARIANT;
       
  1119 
       
  1120     iTransactions.AppendL(&aTransaction);
       
  1121 
       
  1122     __TEST_INVARIANT;
       
  1123     }
       
  1124 
       
  1125 // -----------------------------------------------------------------------------
       
  1126 // CSIPConnectionImplementation::RemoveTransaction
       
  1127 // -----------------------------------------------------------------------------
       
  1128 //
       
  1129 void CSIPConnectionImplementation::RemoveTransaction(
       
  1130 									const CSIPTransactionBase& aTransaction)
       
  1131     {
       
  1132     __TEST_INVARIANT;
       
  1133 
       
  1134     TInt pos = iTransactions.Find(&aTransaction);
       
  1135     if (pos != KErrNotFound)
       
  1136         {
       
  1137         iTransactions.Remove(pos);
       
  1138         }
       
  1139 
       
  1140     __TEST_INVARIANT;
       
  1141     }
       
  1142 
       
  1143 // -----------------------------------------------------------------------------
       
  1144 // CSIPConnectionImplementation::IncomingDialogResponseL
       
  1145 // Response in a dialog or a one that creates a dialog has been received.
       
  1146 // -----------------------------------------------------------------------------
       
  1147 //
       
  1148 void CSIPConnectionImplementation::IncomingDialogResponseL(
       
  1149 											CSIPResponseElements* aElements,
       
  1150 		                                    TUint32 aRequestId,
       
  1151 								            TUint32 aDialogId)
       
  1152     {
       
  1153     __TEST_INVARIANT;
       
  1154 
       
  1155     IncomingResponseToDialogL(aElements, aRequestId, aDialogId, NULL); 
       
  1156     }
       
  1157 
       
  1158 // -----------------------------------------------------------------------------
       
  1159 // CSIPConnectionImplementation::IncomingDialogResponseL
       
  1160 // Refresh related response in a dialog or a one that creates a dialog.
       
  1161 // If error response to an existing refresh, aRequestId is the transactionId of
       
  1162 // a transaction initiated by Refresh subsystem, and not recognized by SIP API.
       
  1163 // -----------------------------------------------------------------------------
       
  1164 //
       
  1165 void CSIPConnectionImplementation::IncomingDialogResponseL(
       
  1166 											CSIPResponseElements* aElements,
       
  1167 		                                    TUint32 aRequestId,
       
  1168                                             TUint32 aRefreshId,
       
  1169 								            TUint32 aDialogId)
       
  1170     {
       
  1171     __TEST_INVARIANT;
       
  1172 
       
  1173     IncomingResponseToDialogL(aElements, aRequestId, aDialogId, &aRefreshId);
       
  1174     }
       
  1175 
       
  1176 // -----------------------------------------------------------------------------
       
  1177 // CSIPConnectionImplementation::IncomingResponseToDialogL
       
  1178 // If forked response, aDialogId won't find the CSIPDialogImplementation, so
       
  1179 // aRequestId is also used for searching.
       
  1180 // -----------------------------------------------------------------------------
       
  1181 //
       
  1182 void CSIPConnectionImplementation::IncomingResponseToDialogL(
       
  1183 											CSIPResponseElements* aElements,
       
  1184 		                                    TUint32 aRequestId,
       
  1185                                             TUint32 aDialogId,
       
  1186                                             TUint32* aRefreshId)
       
  1187     {
       
  1188     __TEST_INVARIANT;
       
  1189     __SIP_ASSERT_LEAVE(aElements != NULL, KErrArgument);
       
  1190 
       
  1191     CSIPDialogImplementation* dialog = FindDialog(aDialogId);
       
  1192     if (!dialog)
       
  1193     	{
       
  1194     	dialog = FindDialogByRequestId(aRequestId);
       
  1195     	}
       
  1196 
       
  1197     if (dialog)
       
  1198         {
       
  1199         TBool useCallback = EFalse;
       
  1200         if (aRefreshId)
       
  1201             {
       
  1202             useCallback = dialog->IncomingResponseL(aElements,
       
  1203 		                                            aRequestId,
       
  1204                                                     *aRefreshId,
       
  1205                                                     aDialogId,
       
  1206                                                     *iCallbackInfo);
       
  1207             }
       
  1208         else
       
  1209             {
       
  1210             useCallback = dialog->IncomingResponseL(aElements,
       
  1211 		                                            aRequestId,
       
  1212                                                     aDialogId,
       
  1213                                                     *iCallbackInfo);
       
  1214             }
       
  1215         if (useCallback)
       
  1216             {
       
  1217             iCallbackInfo->ExecuteCallback(iObserver);
       
  1218             }
       
  1219         }
       
  1220     else
       
  1221         {
       
  1222         delete aElements;
       
  1223         }
       
  1224     }
       
  1225 
       
  1226 // -----------------------------------------------------------------------------
       
  1227 // CSIPConnectionImplementation::__DbgTestInvariant
       
  1228 // -----------------------------------------------------------------------------
       
  1229 //
       
  1230 
       
  1231 void CSIPConnectionImplementation::__DbgTestInvariant() const
       
  1232 	{
       
  1233     if (!iClientConnection)
       
  1234 		{	
       
  1235 		User::Invariant();
       
  1236 		}
       
  1237 	}