|
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 : SIPNotifyDialogAssoc.cpp |
|
15 // Part of : SIPAPI |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "sip.h" |
|
22 #include "siperr.h" |
|
23 #include "sipnotifydialogassoc.h" |
|
24 #include "SipDialogAssocImplementation.h" |
|
25 #include "SipDialogImplementation.h" |
|
26 #include "SipConnectionImplementation.h" |
|
27 #include "sipservertransaction.h" |
|
28 #include "sipclientconnection.h" |
|
29 #include "sipmessageelements.h" |
|
30 #include "sipeventheader.h" |
|
31 #include "sipsubscriptionstateheader.h" |
|
32 #include "SipAssert.h" |
|
33 #include "sipstrings.h" |
|
34 #include "sipstrconsts.h" |
|
35 #include "MessageHeaderCleanup.h" |
|
36 |
|
37 #ifdef CPPUNIT_TEST |
|
38 |
|
39 #include "TestCleanupStack.h" |
|
40 |
|
41 #undef EXPORT_C |
|
42 #define EXPORT_C |
|
43 |
|
44 #endif |
|
45 |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CSIPNotifyDialogAssoc::NewL |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C CSIPNotifyDialogAssoc* |
|
52 CSIPNotifyDialogAssoc::NewL(CSIPServerTransaction& aTransaction, |
|
53 CSIPEventHeader* aEvent, |
|
54 CSIPSubscriptionStateHeader* aState) |
|
55 { |
|
56 CSIPNotifyDialogAssoc* self = |
|
57 CSIPNotifyDialogAssoc::NewLC(aTransaction, aEvent, aState); |
|
58 CleanupStack::Pop(self); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CSIPNotifyDialogAssoc::NewLC |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 EXPORT_C CSIPNotifyDialogAssoc* |
|
67 CSIPNotifyDialogAssoc::NewLC(CSIPServerTransaction& aTransaction, |
|
68 CSIPEventHeader* aEvent, |
|
69 CSIPSubscriptionStateHeader* aState) |
|
70 { |
|
71 CSIPNotifyDialogAssoc* self = new (ELeave) CSIPNotifyDialogAssoc(); |
|
72 CleanupStack::PushL(self); |
|
73 self->ConstructL(aTransaction,NULL,aEvent,aState); |
|
74 return self; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CSIPNotifyDialogAssoc::NewL |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C CSIPNotifyDialogAssoc* |
|
82 CSIPNotifyDialogAssoc::NewL(CSIPServerTransaction& aTransaction, |
|
83 const MSIPRegistrationContext& aContext, |
|
84 CSIPEventHeader* aEvent, |
|
85 CSIPSubscriptionStateHeader* aState) |
|
86 { |
|
87 CSIPNotifyDialogAssoc* self = |
|
88 CSIPNotifyDialogAssoc::NewLC(aTransaction, aContext, aEvent, aState); |
|
89 CleanupStack::Pop(self); |
|
90 return self; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CSIPNotifyDialogAssoc::NewLC |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 EXPORT_C CSIPNotifyDialogAssoc* |
|
98 CSIPNotifyDialogAssoc::NewLC(CSIPServerTransaction& aTransaction, |
|
99 const MSIPRegistrationContext& aContext, |
|
100 CSIPEventHeader* aEvent, |
|
101 CSIPSubscriptionStateHeader* aState) |
|
102 { |
|
103 CSIPNotifyDialogAssoc* self = new (ELeave) CSIPNotifyDialogAssoc(); |
|
104 CleanupStack::PushL(self); |
|
105 self->ConstructL(aTransaction,&aContext,aEvent,aState); |
|
106 return self; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CSIPNotifyDialogAssoc::CSIPNotifyDialogAssoc |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 CSIPNotifyDialogAssoc::CSIPNotifyDialogAssoc() |
|
114 { |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CSIPNotifyDialogAssoc::~CSIPNotifyDialogAssoc |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 EXPORT_C CSIPNotifyDialogAssoc::~CSIPNotifyDialogAssoc() |
|
122 { |
|
123 delete iEvent; |
|
124 delete iSubscriptionState; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CSIPNotifyDialogAssoc::Event |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C const CSIPEventHeader& CSIPNotifyDialogAssoc::Event() const |
|
132 { |
|
133 return *iEvent; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CSIPNotifyDialogAssoc::SubscriptionState |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 EXPORT_C CSIPSubscriptionStateHeader& CSIPNotifyDialogAssoc::SubscriptionState() |
|
141 { |
|
142 return *iSubscriptionState; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CSIPNotifyDialogAssoc::SubscriptionState |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C const CSIPSubscriptionStateHeader& |
|
150 CSIPNotifyDialogAssoc::SubscriptionState() const |
|
151 { |
|
152 return *iSubscriptionState; |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CSIPNotifyDialogAssoc::SendNotifyL |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 EXPORT_C CSIPClientTransaction* |
|
160 CSIPNotifyDialogAssoc::SendNotifyL(CSIPMessageElements* aElements) |
|
161 { |
|
162 return Dialog().Implementation().SendNotifyL(*this, aElements); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CSIPNotifyDialogAssoc::DoSendNotifyWithinDialogL |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 CSIPClientTransaction* |
|
170 CSIPNotifyDialogAssoc::DoSendNotifyWithinDialogL(CSIPMessageElements* aElements) |
|
171 { |
|
172 CSIPMessageElements* elem = aElements; |
|
173 if (!aElements) |
|
174 { |
|
175 //CSIPMessageElements is created by SIP Client API, and will be deleted |
|
176 //in all cases. |
|
177 elem = CSIPMessageElements::NewLC(); |
|
178 } |
|
179 |
|
180 TMessageHeaderCleanup headerCleanup(*elem); |
|
181 TCleanupItem cleanupItem(TMessageHeaderCleanup::Cleanup, &headerCleanup); |
|
182 if (aElements) |
|
183 { |
|
184 //CSIPMessageElements is created by application. If leave occurs, the |
|
185 //copied Event and SubscribtionState headers are detached from |
|
186 //CSIPMessageElements, but CSIPMessageElements won't be deleted. |
|
187 //If leave doesn't occur, CSIPMessageElements will be deleted. |
|
188 CleanupStack::PushL(cleanupItem); |
|
189 } |
|
190 |
|
191 CSIPDialogAssocImplementation::CopyHeaderL(*iEvent, |
|
192 *elem, |
|
193 headerCleanup); |
|
194 CSIPDialogAssocImplementation::CopyHeaderL(*iSubscriptionState, |
|
195 *elem, |
|
196 headerCleanup); |
|
197 CSIPClientTransaction* ta = |
|
198 Dialog().Implementation().SendRequestInDialogL( |
|
199 Implementation(), |
|
200 SIPStrings::StringF(SipStrConsts::ENotify), |
|
201 elem); |
|
202 CleanupStack::Pop(); //TCleanupItem or elem |
|
203 return ta; |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CSIPNotifyDialogAssoc::ConstructL |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 void CSIPNotifyDialogAssoc::ConstructL(CSIPServerTransaction& aTransaction, |
|
211 const MSIPRegistrationContext* aContext, |
|
212 CSIPEventHeader* aEvent, |
|
213 CSIPSubscriptionStateHeader* aState) |
|
214 { |
|
215 __ASSERT_ALWAYS( |
|
216 aTransaction.Type() == SIPStrings::StringF(SipStrConsts::ESubscribe) || |
|
217 aTransaction.Type() == SIPStrings::StringF(SipStrConsts::ERefer), |
|
218 User::Leave(KErrArgument)); |
|
219 |
|
220 CSIPTransactionBase::TState state = aTransaction.StateL(); |
|
221 __ASSERT_ALWAYS(state == CSIPTransactionBase::ETrying || |
|
222 state == CSIPTransactionBase::EProceeding, |
|
223 User::Leave(KErrSIPInvalidTransactionState)); |
|
224 __ASSERT_ALWAYS(aEvent && aState, User::Leave(KErrArgument)); |
|
225 |
|
226 CSIPDialogImplementation* dialogImpl = aTransaction.Dialog(); |
|
227 TBool createNewDialog = (dialogImpl == NULL); |
|
228 if (createNewDialog) |
|
229 { |
|
230 //Push dialogImpl to CleanupStack until it has been associated with |
|
231 //CSIPNotifyDialogAssoc, using CSIPDialogAssocBase::ConstructL(). |
|
232 //Once associated, it is deleted if CSIPNotifyDialogAssoc is deleted. |
|
233 dialogImpl = CSIPDialogImplementation::NewLC( |
|
234 aTransaction.SIPConnectionL().Implementation(),aContext); |
|
235 } |
|
236 |
|
237 //Associates CSIPDialogImplementation with CSIPNotifyDialogAssoc |
|
238 CSIPDialogAssocBase::ConstructL(SIPStrings::StringF(SipStrConsts::ENotify), |
|
239 dialogImpl->Dialog(),aTransaction); |
|
240 if (createNewDialog) |
|
241 { |
|
242 CleanupStack::Pop(dialogImpl); |
|
243 dialogImpl->InitialTransactionReceivedL(aTransaction); |
|
244 } |
|
245 |
|
246 iEvent = aEvent; |
|
247 iSubscriptionState = aState; |
|
248 } |