realtimenetprots/sipfw/SIP/sipapi/src/sipreferdialogassoc.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2004-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          : SIPReferDialogAssoc.cpp
       
    15 // Part of       : SIPAPI
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include <uri8.h>
       
    22 #include "sip.h"
       
    23 #include "siperr.h"
       
    24 #include "sipreferdialogassoc.h"
       
    25 #include "SipDialogAssocImplementation.h"
       
    26 #include "SipDialogImplementation.h"
       
    27 #include "SipConnectionImplementation.h"
       
    28 #include "sipservertransaction.h"
       
    29 #include "sipclientconnection.h"
       
    30 #include "sipregistrationcontext.h"
       
    31 #include "sipmessageelements.h"
       
    32 #include "siptoheader.h"
       
    33 #include "sipfromheader.h"
       
    34 #include "sipcontactheader.h"
       
    35 #include "siprefertoheader.h"
       
    36 #include "SipAssert.h"
       
    37 #include "sipstrings.h"
       
    38 #include "sipstrconsts.h"
       
    39 #include "MessageHeaderCleanup.h"
       
    40 
       
    41 #ifdef CPPUNIT_TEST
       
    42 
       
    43 #include "TestCleanupStack.h"
       
    44 
       
    45 #undef EXPORT_C
       
    46 #define EXPORT_C
       
    47 
       
    48 #endif
       
    49 
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CSIPReferDialogAssoc::NewL
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 EXPORT_C CSIPReferDialogAssoc*
       
    56 CSIPReferDialogAssoc::NewL(CSIPDialog& aDialog, CSIPReferToHeader* aReferTo)
       
    57     {
       
    58     CSIPReferDialogAssoc* self = CSIPReferDialogAssoc::NewLC(aDialog, aReferTo);
       
    59     CleanupStack::Pop(self);
       
    60     return self;
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CSIPReferDialogAssoc::NewLC
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CSIPReferDialogAssoc*
       
    68 CSIPReferDialogAssoc::NewLC(CSIPDialog& aDialog, CSIPReferToHeader* aReferTo)
       
    69     {
       
    70     __ASSERT_ALWAYS(aReferTo, User::Leave(KErrArgument));
       
    71 
       
    72     CSIPReferDialogAssoc* self = new (ELeave) CSIPReferDialogAssoc();
       
    73     CleanupStack::PushL(self);
       
    74     self->CSIPDialogAssocBase::ConstructL(
       
    75     							SIPStrings::StringF(SipStrConsts::ERefer),
       
    76     							aDialog);
       
    77     self->iReferTo = aReferTo;
       
    78     return self;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CSIPReferDialogAssoc::NewL
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C CSIPReferDialogAssoc*
       
    86 CSIPReferDialogAssoc::NewL(CSIPConnection& aConnection,
       
    87 		                   CSIPFromHeader* aFrom,
       
    88 						   CUri8* aRemoteUri,
       
    89 						   CSIPReferToHeader* aReferTo,
       
    90 		                   CSIPToHeader* aTo,
       
    91 		                   CSIPContactHeader* aContact)
       
    92     {    
       
    93     CSIPReferDialogAssoc* self = CSIPReferDialogAssoc::NewLC(aConnection,
       
    94                                                              aFrom,
       
    95                                                              aRemoteUri,
       
    96                                                              aReferTo,
       
    97                                                              aTo,                                                             
       
    98                                                              aContact);
       
    99     CleanupStack::Pop(self);
       
   100     return self;
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CSIPReferDialogAssoc::NewLC
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 EXPORT_C CSIPReferDialogAssoc*
       
   108 CSIPReferDialogAssoc::NewLC(CSIPConnection& aConnection,
       
   109 		                    CSIPFromHeader* aFrom,
       
   110 						    CUri8* aRemoteUri,
       
   111 						    CSIPReferToHeader* aReferTo,
       
   112 		                    CSIPToHeader* aTo,
       
   113 		                    CSIPContactHeader* aContact)
       
   114     {
       
   115     __ASSERT_ALWAYS(aFrom, User::Leave(KErrArgument));
       
   116     return CSIPReferDialogAssoc::NewLC(aConnection,
       
   117 									   aRemoteUri,
       
   118 									   aReferTo,
       
   119 									   aFrom,
       
   120                                 	   aTo,
       
   121 			                    	   aContact,
       
   122 			                    	   NULL);
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CSIPReferDialogAssoc::NewL
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 EXPORT_C CSIPReferDialogAssoc*
       
   130 CSIPReferDialogAssoc::NewL(CSIPConnection& aConnection,                                    
       
   131 		                   CUri8* aRemoteUri,
       
   132 		                   const MSIPRegistrationContext& aContext,
       
   133 		                   CSIPReferToHeader* aReferTo,
       
   134 		                   CSIPFromHeader* aFrom,
       
   135 			               CSIPToHeader* aTo,
       
   136 			               CSIPContactHeader* aContact)
       
   137     {
       
   138     CSIPReferDialogAssoc* self = CSIPReferDialogAssoc::NewLC(aConnection,
       
   139     														 aRemoteUri,                                                             
       
   140                                                              aContext,
       
   141                                                              aReferTo,                                                             
       
   142                                                              aFrom,
       
   143                                                              aTo,                                                             
       
   144                                                              aContact);
       
   145     CleanupStack::Pop(self);
       
   146     return self;
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CSIPReferDialogAssoc::NewLC
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 EXPORT_C CSIPReferDialogAssoc*
       
   154 CSIPReferDialogAssoc::NewLC(CSIPConnection& aConnection,                                    
       
   155 		                    CUri8* aRemoteUri,
       
   156 		                    const MSIPRegistrationContext& aContext,
       
   157 		                    CSIPReferToHeader* aReferTo,
       
   158 		                    CSIPFromHeader* aFrom,
       
   159 			                CSIPToHeader* aTo,
       
   160 			                CSIPContactHeader* aContact)
       
   161     {    
       
   162     __ASSERT_ALWAYS(aContext.IsContextActive(),
       
   163                     User::Leave(KErrSIPInvalidRegistrationState));
       
   164 	return CSIPReferDialogAssoc::NewLC(aConnection,
       
   165 									   aRemoteUri,
       
   166 									   aReferTo,
       
   167 									   aFrom,
       
   168                                 	   aTo,
       
   169 			                    	   aContact,
       
   170 			                    	   &aContext);
       
   171     }
       
   172  
       
   173 // -----------------------------------------------------------------------------
       
   174 // CSIPReferDialogAssoc::NewLC
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 CSIPReferDialogAssoc*
       
   178 CSIPReferDialogAssoc::NewLC(CSIPConnection& aConnection,
       
   179 								CUri8* aRemoteUri,
       
   180 								CSIPReferToHeader* aReferTo,
       
   181 								CSIPFromHeader* aFrom,
       
   182                                 CSIPToHeader* aTo,
       
   183 			                    CSIPContactHeader* aContact,
       
   184 			                    const MSIPRegistrationContext* aContext)
       
   185     {    
       
   186     __ASSERT_ALWAYS(aRemoteUri && aReferTo, User::Leave(KErrArgument));	
       
   187 
       
   188 	CSIPDialogImplementation* dialogImpl =
       
   189 			CSIPDialogImplementation::NewLC(aConnection.Implementation(),
       
   190 											aContext);
       
   191 	CSIPReferDialogAssoc* self =
       
   192     	CSIPReferDialogAssoc::NewL(dialogImpl->Dialog(), aReferTo);
       
   193     //Don't take ownership of aReferTo yet, as leave can occur
       
   194     self->iReferTo = NULL;
       
   195 
       
   196     CleanupStack::Pop(dialogImpl);
       
   197     CleanupStack::PushL(self);
       
   198 
       
   199 	dialogImpl->SetHeadersL(aFrom, aTo, aRemoteUri, aContact);
       
   200     self->iReferTo = aReferTo;
       
   201 
       
   202     return self;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CSIPReferDialogAssoc::CSIPReferDialogAssoc
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 CSIPReferDialogAssoc::CSIPReferDialogAssoc()    
       
   210     {
       
   211     }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CSIPReferDialogAssoc::~CSIPReferDialogAssoc
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 EXPORT_C CSIPReferDialogAssoc::~CSIPReferDialogAssoc()
       
   218     {
       
   219     delete iReferTo;
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CSIPReferDialogAssoc::ReferTo
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 EXPORT_C const CSIPReferToHeader& CSIPReferDialogAssoc::ReferTo() const
       
   227 	{
       
   228 	return *iReferTo;
       
   229 	}
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CSIPReferDialogAssoc::SendReferL
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 EXPORT_C CSIPClientTransaction*
       
   236 CSIPReferDialogAssoc::SendReferL(CSIPMessageElements* aElements)
       
   237     {     
       
   238     return Dialog().Implementation().SendReferL(*this, aElements);
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CSIPReferDialogAssoc::DoSendReferL
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 CSIPClientTransaction*
       
   246 CSIPReferDialogAssoc::DoSendReferL(CSIPMessageElements* aElements,
       
   247 								   TBool aWithinDialog)
       
   248     {
       
   249 	CSIPMessageElements* elem = aElements;
       
   250     if (!aElements)
       
   251     	{
       
   252     	elem = CSIPMessageElements::NewLC();
       
   253     	}
       
   254 
       
   255     TMessageHeaderCleanup headerCleanup(*elem);
       
   256     TCleanupItem cleanupItem(TMessageHeaderCleanup::Cleanup, &headerCleanup);
       
   257     if (aElements)
       
   258     	{
       
   259     	CleanupStack::PushL(cleanupItem);
       
   260     	}
       
   261 	CSIPDialogAssocImplementation::CopyHeaderL(*iReferTo, *elem, headerCleanup);
       
   262 	
       
   263 	CSIPClientTransaction* ta = NULL;
       
   264 	if (aWithinDialog)
       
   265 		{
       
   266 		ta = Dialog().Implementation().SendRequestInDialogL(Implementation(),
       
   267 															Type(),
       
   268 															elem);
       
   269 		}
       
   270 	else
       
   271 		{
       
   272 		const CSIPContactHeader* contact =
       
   273 			Dialog().Implementation().ContactHeader();
       
   274 		if (contact)
       
   275 			{
       
   276 			CSIPDialogAssocImplementation::CopyHeaderL(*contact,
       
   277 													   *elem,
       
   278 													   headerCleanup);
       
   279 			}
       
   280 
       
   281 		ta = Dialog().Implementation().SendDialogCreatingRequestL(
       
   282 											Implementation(), elem);	    
       
   283 		}
       
   284 	CleanupStack::Pop(); //TCleanupItem or elem
       
   285 	return ta;	
       
   286     }