realtimenetprots/sipfw/SIP/sipapi/src/sipservertransaction.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          : SIPServerTransaction.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 "transactionassociation.h"
       
    25 #include "sipservertransaction.h"
       
    26 #include "siprequestelements.h"
       
    27 #include "csipresponsesender.h"
       
    28 #include "sipstrings.h"
       
    29 #include "sipstrconsts.h"
       
    30 
       
    31 #ifdef CPPUNIT_TEST
       
    32 
       
    33 #include "TestCleanupStack.h"
       
    34 
       
    35 #undef EXPORT_C
       
    36 #define EXPORT_C
       
    37 
       
    38 #endif
       
    39 
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CSIPServerTransaction::NewL
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CSIPServerTransaction*
       
    46 CSIPServerTransaction::NewL(TUint32 aRequestId,
       
    47                             MTransactionAssociation& aAssociation,
       
    48                             CSIPRequestElements* aElements)
       
    49     {
       
    50     CSIPServerTransaction* self =
       
    51         CSIPServerTransaction::NewLC(aRequestId, aAssociation, aElements);
       
    52     CleanupStack::Pop(self);
       
    53     return self;
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CSIPServerTransaction::NewLC
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CSIPServerTransaction*
       
    61 CSIPServerTransaction::NewLC(TUint32 aRequestId,
       
    62                              MTransactionAssociation& aAssociation,
       
    63                              CSIPRequestElements* aElements)
       
    64     {
       
    65     __ASSERT_ALWAYS(aElements, User::Leave(KErrArgument));
       
    66 
       
    67     CSIPServerTransaction* self =
       
    68         new (ELeave) CSIPServerTransaction(aRequestId, aAssociation);
       
    69     CleanupStack::PushL(self);
       
    70     self->ConstructL(aElements);
       
    71     return self;
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CSIPServerTransaction::CSIPServerTransaction
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CSIPServerTransaction::CSIPServerTransaction(TUint32 aRequestId,
       
    79                                     MTransactionAssociation& aAssociation ) :
       
    80     CSIPTransactionBase(EFalse, aRequestId, aAssociation)
       
    81     {
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CSIPServerTransaction::ConstructL
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CSIPServerTransaction::ConstructL(CSIPRequestElements* aElements)
       
    89     {
       
    90     __ASSERT_ALWAYS(aElements, User::Leave(KErrArgument));
       
    91 
       
    92     CSIPTransactionBase::ConstructL(aElements->Method());
       
    93 
       
    94     //Create default sender
       
    95     iResponseSender = CSIPResponseSender::NewL();
       
    96 
       
    97     //Take ownership of aElements when leave can't occur
       
    98     iRequestElements = aElements;
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CSIPServerTransaction::~CSIPServerTransaction
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C CSIPServerTransaction::~CSIPServerTransaction()
       
   106     {
       
   107     delete iRequestElements;
       
   108     delete iResponseSender;    
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CSIPServerTransaction::SendResponseL
       
   113 // CSIPResponseElements checks the response is not a 100
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 EXPORT_C void
       
   117 CSIPServerTransaction::SendResponseL(CSIPResponseElements* aElements)
       
   118     {
       
   119     __TEST_INVARIANT;
       
   120     __ASSERT_ALWAYS(aElements, User::Leave(KErrArgument));
       
   121     __ASSERT_ALWAYS(ResponseAllowed(), User::Leave(KErrGeneral));
       
   122 
       
   123     CSIPTransactionBase::TState state = StateL();
       
   124     __ASSERT_ALWAYS(state == CSIPTransactionBase::ETrying ||
       
   125                     state == CSIPTransactionBase::EProceeding,
       
   126                     User::Leave(KErrSIPInvalidTransactionState));    
       
   127 
       
   128     CheckAssociationL();
       
   129     iResponseSender->SendResponseL(iAssociation->ClientConnectionL(),
       
   130                                    *aElements,
       
   131                                    RequestId(),
       
   132                                    AffectsDialogState(),
       
   133                                    IsTargetRefresh(Type()));
       
   134     SetResponseElements(aElements);
       
   135 
       
   136     __TEST_INVARIANT;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CSIPServerTransaction::RequestElements
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 EXPORT_C const CSIPRequestElements*
       
   144 CSIPServerTransaction::RequestElements() const
       
   145     {
       
   146     __TEST_INVARIANT;
       
   147     return iRequestElements;
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CSIPServerTransaction::ResponseAllowed
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C TBool CSIPServerTransaction::ResponseAllowed() const
       
   155     {
       
   156     __TEST_INVARIANT;
       
   157     return (Type() != SIPStrings::StringF(SipStrConsts::EAck));
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CSIPServerTransaction::SetResponseSender
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 void CSIPServerTransaction::SetResponseSender(MSIPResponseSender* aSender)
       
   165     {
       
   166     __TEST_INVARIANT;
       
   167     __ASSERT_DEBUG(aSender,
       
   168 		User::Panic(_L("CSIPServerTransaction::SetRespSender() aSender = 0"),
       
   169 		KErrArgument));
       
   170 
       
   171     delete iResponseSender;
       
   172     iResponseSender = aSender;
       
   173 
       
   174     __TEST_INVARIANT;
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CSIPServerTransaction::Dialog
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 CSIPDialogImplementation* CSIPServerTransaction::Dialog() const
       
   182 	{
       
   183 	__TEST_INVARIANT;
       
   184 	return iResponseSender->Dialog();
       
   185 	}
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CSIPServerTransaction::SIPConnectionL
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 CSIPConnection& CSIPServerTransaction::SIPConnectionL()
       
   192     {
       
   193     CheckAssociationL();
       
   194 
       
   195     return iAssociation->SIPConnectionL();
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CSIPServerTransaction::ReAssociateL
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CSIPServerTransaction::ReAssociateL(MTransactionAssociation& aAssociation)
       
   203     {
       
   204     __TEST_INVARIANT;
       
   205     CheckAssociationL();
       
   206 
       
   207     //Attach transaction to the new association
       
   208     aAssociation.AddTransactionL(*this);
       
   209     
       
   210     //Clear previous association only after attaching has succeeded
       
   211     iAssociation->RemoveTransaction(*this);
       
   212 
       
   213     iAssociation = &aAssociation;
       
   214 
       
   215     __TEST_INVARIANT;
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CSIPServerTransaction::DetachRequestElements
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void CSIPServerTransaction::DetachRequestElements(TAny* aServerTransaction)
       
   223 	{
       
   224     __SIP_ASSERT_RETURN(aServerTransaction, KErrArgument);
       
   225 
       
   226     reinterpret_cast<CSIPServerTransaction*>(aServerTransaction)->
       
   227         iRequestElements = NULL;
       
   228 	}
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CSIPServerTransaction::__DbgTestInvariant
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 
       
   235 void CSIPServerTransaction::__DbgTestInvariant() const
       
   236 	{
       
   237 	if (iResponseSender == NULL)
       
   238 		{	
       
   239 		User::Invariant();
       
   240 		}
       
   241 	}