|
1 // Copyright (c) 2006-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 : ServerTransaction.cpp |
|
15 // Part of : Transaction |
|
16 // Version : SIP/5.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "SipAssert.h" |
|
22 #include "siperr.h" |
|
23 #include "sipstrings.h" |
|
24 #include "sipstrconsts.h" |
|
25 #include "siprequest.h" |
|
26 #include "sipresponse.h" |
|
27 #include "UserAgentBase.h" |
|
28 #include "SIPMessageUtility.h" |
|
29 |
|
30 #include "ServerTransaction.h" |
|
31 #include "ResponseQueue.h" |
|
32 #include "ResponseQueueItem.h" |
|
33 #include "Transmitter.h" |
|
34 |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CServerTransaction::CServerTransaction |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CServerTransaction::CServerTransaction(CUserAgentBase& aUserAgent, |
|
41 CTransmitter& aTransmitter, |
|
42 MTimerManager& aTimers, |
|
43 CTransactionState& aInitialState, |
|
44 TTimerValues& aTimerValues) : |
|
45 CTransaction(aUserAgent, |
|
46 aTransmitter, |
|
47 aTimers, |
|
48 aInitialState, |
|
49 aTimerValues) |
|
50 { |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CServerTransaction::ConstructServerTaL |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 void CServerTransaction::ConstructServerTaL() |
|
58 { |
|
59 iSendQueue = CResponseQueue::NewL(); |
|
60 iSentResponses = CResponseQueue::NewL(); |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CServerTransaction::~CServerTransaction |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CServerTransaction::~CServerTransaction() |
|
68 { |
|
69 delete iOutgoingMsg; |
|
70 delete iSendQueue; |
|
71 delete iSentResponses; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CServerTransaction::PassRequestToUserAgentL |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 void CServerTransaction::PassRequestToUserAgentL(CSIPRequest* aReq) |
|
79 { |
|
80 __TEST_INVARIANT; |
|
81 __SIP_ASSERT_LEAVE(aReq, KErrArgument); |
|
82 __SIP_ASSERT_LEAVE(iUserAgent, KErrNotFound); |
|
83 __SIP_ASSERT_LEAVE(!iRequestPassedToUA, KErrAlreadyExists); |
|
84 |
|
85 iUserAgent->ReceiveL(aReq); |
|
86 iRequestPassedToUA = ETrue; |
|
87 |
|
88 __TEST_INVARIANT; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CServerTransaction::RequestPassedToUA |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 TBool CServerTransaction::RequestPassedToUA() const |
|
96 { |
|
97 __TEST_INVARIANT; |
|
98 return iRequestPassedToUA; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CServerTransaction::Create100L |
|
103 // If no To-tag in aReq, it is not added to response. |
|
104 // iOutgoingMsg can theorically already have 100, if leave occurs after |
|
105 // Create100L and a retransmitted request is received before transaction stops. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CServerTransaction::Create100L(CSIPRequest& aReq) |
|
109 { |
|
110 __TEST_INVARIANT; |
|
111 if (!iOutgoingMsg) |
|
112 { |
|
113 CSIPResponse* resp = CSIPResponse::NewLC(100, |
|
114 SIPStrings::StringF(SipStrConsts::EPhraseTrying)); |
|
115 |
|
116 CSIPMessageUtility::CopyHeadersL(aReq, *resp, |
|
117 SIPStrings::StringF(SipStrConsts::EToHeader)); |
|
118 CSIPMessageUtility::CopyHeadersL(aReq, *resp, |
|
119 SIPStrings::StringF(SipStrConsts::EFromHeader)); |
|
120 CSIPMessageUtility::CopyHeadersL(aReq, *resp, |
|
121 SIPStrings::StringF(SipStrConsts::ECallIDHeader)); |
|
122 CSIPMessageUtility::CopyHeadersL(aReq, *resp, |
|
123 SIPStrings::StringF(SipStrConsts::ECSeqHeader)); |
|
124 CSIPMessageUtility::CopyHeadersL(aReq, *resp, |
|
125 SIPStrings::StringF(SipStrConsts::EViaHeader)); |
|
126 |
|
127 CleanupStack::Pop(resp); |
|
128 iOutgoingMsg = resp; |
|
129 } |
|
130 |
|
131 __TEST_INVARIANT; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CServerTransaction::SendToTransmitterL |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CServerTransaction::SendToTransmitterL() |
|
139 { |
|
140 __TEST_INVARIANT; |
|
141 __SIP_ASSERT_LEAVE(iOutgoingMsg, KErrNotFound); |
|
142 __SIP_ASSERT_LEAVE(!iOutgoingMsg->IsRequest(), KErrSIPMalformedMessage); |
|
143 |
|
144 iTransmitter->SendResponseL(static_cast<CSIPResponse&>(*iOutgoingMsg), |
|
145 iTransportParams, |
|
146 this, |
|
147 TransactionId()); |
|
148 __TEST_INVARIANT; |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CServerTransaction::SendAndStoreResponseL |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CServerTransaction::SendAndStoreResponseL(CResponseQueueItem* aRespItem) |
|
156 { |
|
157 __TEST_INVARIANT; |
|
158 __SIP_ASSERT_LEAVE(aRespItem, KErrArgument); |
|
159 __SIP_ASSERT_LEAVE(CSIPMessageUtility::CheckTransport(iTransportProtocol), |
|
160 KErrArgument); |
|
161 |
|
162 SendAndStoreResponseL(aRespItem, iTransportProtocol); |
|
163 |
|
164 __TEST_INVARIANT; |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CServerTransaction::SendAndStoreResponseL |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 void CServerTransaction::SendAndStoreResponseL(CResponseQueueItem* aRespItem, |
|
172 RStringF aTransportProtocol) |
|
173 { |
|
174 __TEST_INVARIANT; |
|
175 __SIP_ASSERT_LEAVE(aRespItem, KErrArgument); |
|
176 __SIP_ASSERT_LEAVE(CSIPMessageUtility::CheckTransport(aTransportProtocol), |
|
177 KErrArgument); |
|
178 |
|
179 CResponseQueueItem* previousRespItem = NULL; |
|
180 if (iOutgoingMsg) |
|
181 { |
|
182 //Earlier response must be a 1xx, as UAS sends only one final response. |
|
183 __ASSERT_DEBUG(!CSIPMessageUtility::IsFinalResponse( |
|
184 static_cast<CSIPResponse&>(*iOutgoingMsg)), |
|
185 User::Panic(_L("ServTa:SendAndStoreRespL"), KErrAlreadyExists)); |
|
186 previousRespItem = |
|
187 CResponseQueueItem::NewLC(static_cast<CSIPResponse*>(iOutgoingMsg), |
|
188 iTransportParams, |
|
189 //aRespItem has same value for "is INVITE" |
|
190 aRespItem->IsRespToInvite()); |
|
191 } |
|
192 |
|
193 iTransmitter->SendResponseL(aRespItem->Response(), |
|
194 aRespItem->TransportParams(), |
|
195 this, |
|
196 TransactionId()); |
|
197 if (iOutgoingMsg) |
|
198 { |
|
199 TInt status = iSentResponses->Add(previousRespItem); |
|
200 if (status != KErrNone) |
|
201 { |
|
202 //ConnectionMgr must not use the response |
|
203 iTransmitter->CancelSendResponses(TransactionId(), ETrue); |
|
204 User::Leave(status); |
|
205 } |
|
206 CleanupStack::Pop(previousRespItem); |
|
207 } |
|
208 |
|
209 iTransportProtocol = aTransportProtocol; |
|
210 iTransportParams = aRespItem->TransportParams(); |
|
211 |
|
212 iOutgoingMsg = &aRespItem->Response(); |
|
213 aRespItem->SetResponseOwnership(EFalse); |
|
214 delete aRespItem; |
|
215 |
|
216 __TEST_INVARIANT; |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CServerTransaction::AddResponseToSendQueueL |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void |
|
224 CServerTransaction::AddResponseToSendQueueL(CResponseQueueItem* aRespItem) const |
|
225 { |
|
226 __TEST_INVARIANT; |
|
227 __SIP_ASSERT_LEAVE(aRespItem, KErrArgument); |
|
228 |
|
229 User::LeaveIfError(iSendQueue->Add(aRespItem)); |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CServerTransaction::GetResponseFromSendQueue |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 CResponseQueueItem* CServerTransaction::GetResponseFromSendQueue() const |
|
237 { |
|
238 __TEST_INVARIANT; |
|
239 return iSendQueue->GetNext(); |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CServerTransaction::IcmpErrorL |
|
244 // ServerTransaction ignores ICMP error |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 void CServerTransaction::IcmpErrorL(const TInetAddr& /*aAddress*/, |
|
248 CSipConnectionMgr::TICMPError /*aError*/) |
|
249 { |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CServerTransaction::TerminatedL |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 void CServerTransaction::TerminatedL(TInt aReason) |
|
257 { |
|
258 __TEST_INVARIANT; |
|
259 |
|
260 if (!iTerminated) |
|
261 { |
|
262 if (iTransmitter) |
|
263 { |
|
264 //Responses will be deleted, ConnectionMgr must not use them. |
|
265 iTransmitter->CancelSendResponses(TransactionId(), |
|
266 !IsInviteTransaction()); |
|
267 } |
|
268 |
|
269 CTransaction::TerminatedL(aReason); |
|
270 } |
|
271 |
|
272 __TEST_INVARIANT; |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CServerTransaction::__DbgTestInvariant |
|
277 // ----------------------------------------------------------------------------- |
|
278 // |
|
279 |
|
280 void CServerTransaction::__DbgTestInvariant() const |
|
281 { |
|
282 if (!iSendQueue || !iSentResponses) |
|
283 { |
|
284 User::Invariant(); |
|
285 } |
|
286 } |
|
287 |