realtimenetprots/sipfw/SIP/sipapi/src/sipdialogtrying.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2003-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          : sipdialogtrying.cpp
       
    15 // Part of       : SIPAPI
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "SipAssert.h"
       
    22 #include "sip.h"
       
    23 #include "siperr.h"
       
    24 #include "siptoheader.h"
       
    25 #include "SipConnectionImplementation.h"
       
    26 #include "sipclientconnection.h"
       
    27 #include "sipdialogtrying.h"
       
    28 #include "SipDialogImplementation.h"
       
    29 #include "sipclienttransaction.h"
       
    30 #include "sipservertransaction.h"
       
    31 #include "sipmessageelements.h"
       
    32 #include "sipresponseelements.h"
       
    33 #include "sipinvitedialogassoc.h"
       
    34 #include "sipsubscribedialogassoc.h"
       
    35 #include "sipreferdialogassoc.h"
       
    36 #include "sipconnectioncallback.h"
       
    37 #include "sipstrings.h"
       
    38 #include "sipstrconsts.h"
       
    39 
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CDialogTrying::NewL
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CDialogTrying* CDialogTrying::NewL()
       
    46     {
       
    47     return new (ELeave) CDialogTrying();
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CDialogTrying::CDialogTrying
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CDialogTrying::CDialogTrying()
       
    55 	{
       
    56 	}
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CDialogTrying::~CDialogTrying
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CDialogTrying::~CDialogTrying()
       
    63 	{
       
    64 	}
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CDialogTrying::State
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CSIPDialog::TState CDialogTrying::State() const
       
    71     {
       
    72     return CSIPDialog::EInit;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CDialogTrying::SetNeighbourStates
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CDialogTrying::SetNeighbourStates(CDialogState& aEarly,
       
    80                                        CDialogState& aConfirmed,
       
    81                                        CDialogState& aTerminated)
       
    82     {
       
    83     iEarly = &aEarly;
       
    84     iConfirmed = &aConfirmed;
       
    85     iTerminated = &aTerminated;
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CDialogTrying::SendInviteL
       
    90 // Only the initial request creating the dialog, can be sent in Trying state.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CSIPClientTransaction*
       
    94 CDialogTrying::SendInviteL(const CSIPDialogImplementation& aDialog,                           
       
    95                            CSIPInviteDialogAssoc& aAssoc,
       
    96                            CSIPMessageElements* aElements) const
       
    97     {    
       
    98     aDialog.CheckNoTransactionExistsL();
       
    99     return aAssoc.DoSendInviteL(aElements);
       
   100 	}
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CDialogTrying::SendSubscribeL
       
   104 // Only the initial request creating the dialog, can be sent in Trying state.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 CSIPClientTransaction*
       
   108 CDialogTrying::SendSubscribeL(const CSIPDialogImplementation& aDialog,
       
   109                               CSIPSubscribeDialogAssoc& aAssoc,
       
   110                               CSIPMessageElements* aElements,
       
   111                               CSIPRefresh* aRefresh) const
       
   112     {    
       
   113     aDialog.CheckNoTransactionExistsL();
       
   114     return aAssoc.DoSendSubscribeL(aElements, aRefresh, EFalse);    
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CDialogTrying::SendReferL
       
   119 // Only the initial request creating the dialog, can be sent in Trying state.
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 CSIPClientTransaction*
       
   123 CDialogTrying::SendReferL(const CSIPDialogImplementation& aDialog,
       
   124 						  CSIPReferDialogAssoc& aAssoc,
       
   125                    		  CSIPMessageElements* aElements) const
       
   126   	{
       
   127   	aDialog.CheckNoTransactionExistsL();
       
   128 	return aAssoc.DoSendReferL(aElements, EFalse);
       
   129   	}
       
   130               
       
   131 // -----------------------------------------------------------------------------
       
   132 // CDialogTrying::SendResponseL
       
   133 // This is the first response sent and it can't be a 100 response. A 101-299
       
   134 // response creates a dialog, a 300-699 response does not.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CDialogTrying::SendResponseL(CSIPDialogImplementation& aDialog,
       
   138                                   const CSIPResponseElements& aElements,
       
   139 						          TUint32 aRequestId,
       
   140                                   TBool aAffectsDialogState,
       
   141                                   TBool /*aTargetRefresh*/) const
       
   142     {
       
   143     __SIP_ASSERT_LEAVE(aAffectsDialogState, KErrArgument);
       
   144     
       
   145     CSIPConnection* connection = aDialog.Connection();
       
   146     __ASSERT_ALWAYS(connection, User::Leave(KErrSIPResourceNotAvailable));
       
   147 
       
   148 	CSIPClientConnection& client =
       
   149 		connection->Implementation().ClientConnectionL();
       
   150     if (aElements.StatusCode() >= 300)
       
   151         {        
       
   152         client.SendResponseL(aElements, aRequestId);
       
   153         aDialog.ChangeState(iTerminated);
       
   154         }
       
   155     else
       
   156         {        
       
   157         TUint32 dialogId(0);
       
   158         client.SendResponseAndCreateDialogL(aElements, aRequestId, 
       
   159                                             dialogId, aDialog.RegistrationId());       
       
   160         aDialog.SetDialogId(dialogId);
       
   161         aDialog.StoreCallIdL();                
       
   162 		aDialog.FillLocalTagL(EFalse);
       
   163 
       
   164         //Enter next state when the response has been successfully sent
       
   165         if (aElements.StatusCode() >= 200)
       
   166             {
       
   167             aDialog.ChangeState(iConfirmed);
       
   168             }
       
   169         else
       
   170             {                
       
   171             //TransactionUser will add to-tag into other responses than 100
       
   172             aDialog.ChangeState(iEarly);
       
   173             }
       
   174         }    
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CDialogTrying::IncomingResponseL
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 TBool
       
   182 CDialogTrying::IncomingResponseL(CSIPDialogImplementation& aDialog,
       
   183                                  CSIPResponseElements* aElements,
       
   184 		                         TUint32 aRequestId,
       
   185                                  TUint32 /*aDialogId*/,
       
   186                                  CConnectionCallback& aCallback) const
       
   187     {    
       
   188     __SIP_ASSERT_LEAVE(aElements, KErrArgument);    
       
   189 
       
   190     CSIPTransactionBase* ta = NULL;
       
   191     CSIPDialogAssocBase* assoc = NULL;    
       
   192     if (aDialog.FindTransactionAndAssoc(aRequestId, &ta, &assoc))
       
   193         {
       
   194         __SIP_ASSERT_LEAVE(ta->IsSIPClientTransaction(), KErrGeneral);
       
   195         aDialog.UpdateRemoteTargetL(ta->Type(), aElements->MessageElements());
       
   196 
       
   197 		__SIP_ASSERT_LEAVE(aElements->ToHeader() != NULL, KErrArgument);        
       
   198         aDialog.FillRemoteTagL(*aElements->ToHeader());
       
   199 
       
   200         CSIPClientTransaction* clientTa =
       
   201             static_cast<CSIPClientTransaction*>(ta);
       
   202         clientTa->SetResponseElements(aElements);
       
   203 
       
   204         aDialog.UpdateState(*clientTa,
       
   205                             *iEarly,
       
   206                             *iConfirmed,
       
   207                             *iTerminated);
       
   208         aCallback.Set(CConnectionCallback::EIncomingResponse,
       
   209                       clientTa,
       
   210                       NULL,
       
   211                       NULL,
       
   212                       assoc);
       
   213         return ETrue;
       
   214         }
       
   215     
       
   216     //Transaction not found, ignore response
       
   217     delete aElements;
       
   218     return EFalse;
       
   219     }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CDialogTrying::IncomingResponseL
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 TBool CDialogTrying::IncomingResponseL(CSIPDialogImplementation& aDialog,
       
   226                                        CSIPResponseElements* aElements,
       
   227 		                               TUint32 aRequestId,
       
   228                                        TUint32 aRefreshId,
       
   229                                        TUint32 /*aDialogId*/,
       
   230                                        CConnectionCallback& aCallback) const
       
   231     {
       
   232     return ResponseToRefreshL(aDialog,
       
   233                               aElements,
       
   234 		                      aRequestId,
       
   235                               aRefreshId,
       
   236                               aCallback,
       
   237                               *iEarly,
       
   238                               *iConfirmed,
       
   239                               *iTerminated);
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CDialogTrying::IncomingRequestL
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 TBool CDialogTrying::IncomingRequestL(CSIPDialogImplementation& aDialog,
       
   247                                       CSIPServerTransaction* aTransaction,
       
   248                                       CConnectionCallback& aCallback) const
       
   249     {
       
   250     __SIP_ASSERT_LEAVE(aTransaction, KErrArgument);
       
   251 
       
   252     if (aTransaction->Type() == SIPStrings::StringF(SipStrConsts::ENotify) &&
       
   253     	aDialog.DoesNotifyConfirmDialog())
       
   254         {
       
   255         aDialog.ChangeRefreshesToActive();
       
   256         aDialog.ChangeState(iConfirmed);
       
   257         }
       
   258 
       
   259     return RequestReceivedL(aDialog, aTransaction, aCallback);
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CDialogTrying::ErrorOccured
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 TBool CDialogTrying::ErrorOccured(CSIPDialogImplementation& aDialog,
       
   267                                   TInt aError,
       
   268                                   TUint32 aRequestId,
       
   269                                   CConnectionCallback& aCallback) const
       
   270     {
       
   271     return HandleErrorOccurred(aDialog,
       
   272                                aError,
       
   273                                aRequestId,
       
   274                                aCallback,
       
   275                                *iTerminated);
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CDialogTrying::ErrorOccured
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 TBool CDialogTrying::ErrorOccured(CSIPDialogImplementation& aDialog,
       
   283                                   TInt aError,
       
   284                                   TUint32 aRefreshId,
       
   285                                   TUint32 /*aRequestId*/,
       
   286                                   CConnectionCallback& aCallback) const
       
   287     {    
       
   288     return HandleRefreshErrorOccurred(aDialog,
       
   289                                		  aError,
       
   290                                		  aRefreshId,
       
   291                                		  aCallback,
       
   292                                		  *iTerminated);
       
   293     }
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // CDialogTrying::ConnectionLost
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 void CDialogTrying::ConnectionLost(CSIPDialogImplementation& aDialog) const
       
   300     {
       
   301     aDialog.ChangeState(iTerminated);
       
   302     }