realtimenetprots/sipfw/SIP/sipapi/src/unregistering.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2005-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          : unregistering.cpp
       
    15 // Part of       : SIPAPI
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "sip.h"
       
    22 #include "siperr.h"
       
    23 #include "SipAssert.h"
       
    24 #include "unregistering.h"
       
    25 #include "RegBindingImplementation.h"
       
    26 #include "sipclienttransaction.h"
       
    27 #include "sipresponseelements.h"
       
    28 #include "sipconnectioncallback.h"
       
    29 
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CUnregistering::NewL
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CUnregistering* CUnregistering::NewL()
       
    36 	{
       
    37 	return new (ELeave) CUnregistering();
       
    38 	}
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CUnregistering::CUnregistering
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CUnregistering::CUnregistering()
       
    45 	{
       
    46 	}
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CUnregistering::~CUnregistering
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CUnregistering::~CUnregistering()
       
    53 	{
       
    54 	}
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CUnregistering::SetNeighbourStates
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CUnregistering::SetNeighbourStates(CRegistrationState& aRegistered,
       
    61 							            CRegistrationState& aUnregistered)                                      
       
    62 	{	
       
    63     iRegistered = &aRegistered;
       
    64     iUnregistered = &aUnregistered;
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CUnregistering::IncomingResponseL
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 TBool
       
    72 CUnregistering::IncomingResponseL(CRegBindingImplementation& aRegistration,
       
    73                                   CSIPResponseElements* aElements,
       
    74 				                  TUint32 aRequestId,
       
    75 						          TUint32 /*aRegistrationId*/,
       
    76 						          TUint32 aRefreshId,
       
    77 		                          CConnectionCallback& aCallback) const
       
    78     {
       
    79     CSIPClientTransaction* ta = aRegistration.FindTransaction(aRequestId);    
       
    80     CBase* objToDelete = NULL;
       
    81 
       
    82     if (!ta)
       
    83     	{
       
    84     	if (!aRefreshId)
       
    85     		{
       
    86     		delete aElements;
       
    87     		return EFalse;
       
    88     		}
       
    89     	ta = aRegistration.CreateClientTransactionL();
       
    90     	ta->SetRequestId(aRequestId);
       
    91       	objToDelete = ta;
       
    92     	}
       
    93 
       
    94     if (aElements->StatusCode() >= 200)
       
    95         {
       
    96         aRegistration.RemoveRegisteredContact();
       
    97         aRegistration.ChangeState(iUnregistered);
       
    98         }  	
       
    99   	ta->SetResponseElements(aElements);
       
   100 
       
   101 	if (objToDelete && aElements->StatusCode() >= 300)
       
   102 		{
       
   103 		aCallback.Set(CConnectionCallback::EErrorOccuredInRegistration,
       
   104                       NULL,
       
   105                       &aRegistration.Binding(),
       
   106                       NULL,
       
   107                       NULL,
       
   108                       KErrSIPTerminatedWithResponse,
       
   109                       objToDelete);
       
   110         }
       
   111     else
       
   112         {
       
   113         //All responses, also 1xx, are passed to application
       
   114         aCallback.Set(CConnectionCallback::EIncomingResponseInRegistration,
       
   115 	                  ta,
       
   116 	                  &aRegistration.Binding(),
       
   117 	                  NULL,
       
   118 	                  NULL,
       
   119 	                  KErrNone,
       
   120 	                  objToDelete);
       
   121 		}
       
   122 
       
   123 	return ETrue;
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CUnregistering::ErrorOccured
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 TBool CUnregistering::ErrorOccured(CRegBindingImplementation& aRegistration,
       
   131                                    TInt aError,
       
   132                                    TUint32 aRequestId,
       
   133                                    CConnectionCallback& aCallback) const
       
   134     {
       
   135     return aRegistration.HandleError(aCallback,
       
   136     								 aError,
       
   137     								 aRequestId,
       
   138     								 *iUnregistered);
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CUnregistering::ConnectionLost
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void
       
   146 CUnregistering::ConnectionLost(CRegBindingImplementation& aRegistration) const
       
   147     {    
       
   148     aRegistration.ChangeState(iUnregistered);
       
   149     }