|
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 : Early.cpp |
|
15 // Part of : SIPDialogs |
|
16 // Version : SIP/5.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "siperr.h" |
|
23 #include "Early.h" |
|
24 #include "MDialogContext.h" |
|
25 #include "TransactionItemBase.h" |
|
26 #include "SipAssert.h" |
|
27 #include "sipresponse.h" |
|
28 #include "siprequest.h" |
|
29 #include "siptoheader.h" |
|
30 #include "sipfromheader.h" |
|
31 #include "sipcallidheader.h" |
|
32 #include "sipcseqheader.h" |
|
33 #include "CSigCompMgr.h" |
|
34 #include "sipstrings.h" |
|
35 #include "sipstrconsts.h" |
|
36 #include "TSIPTransportParams.h" |
|
37 |
|
38 _LIT8(KEarly, "Early"); |
|
39 const TUint K100Response = 100; |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // TEarly::TEarly |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 TEarly::TEarly (MDialogContext& aDialog, |
|
46 TDialogStateBase& aStateConfirmed, |
|
47 TDialogStateBase& aStateTerminated) |
|
48 : TDialogStateBase(aDialog), |
|
49 iStateConfirmed(aStateConfirmed), |
|
50 iStateTerminated(aStateTerminated) |
|
51 { |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // TEarly::Name |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 const TDesC8& TEarly::Name () const |
|
59 { |
|
60 return KEarly; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // TEarly::SendL |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void TEarly::SendL (TTransactionId& aTransactionId, |
|
68 CSIPRequest* aRequest, |
|
69 CTransactionItemBase& aTransactionItem, |
|
70 CURIContainer& aRemoteTarget) |
|
71 { |
|
72 TSIPTransportParams params(iDialog.TransportParams(KEmptyRegistrationId)); |
|
73 params.SetSkipNaptrAndSrv(iDialog.HasRouteSet()); |
|
74 aTransactionItem.SendL(params,aTransactionId,KEmptyRegistrationId, |
|
75 aRequest,aRemoteTarget); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // TEarly::SendL |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void TEarly::SendL (CTransactionItemBase& aTransactionItem, |
|
83 CSIPResponse* aResponse) |
|
84 { |
|
85 TSIPTransportParams params(iDialog.TransportParams(KEmptyRegistrationId)); |
|
86 // Check that 2xx response is for correct request |
|
87 if(aResponse->Type() == CSIPResponse::E2XX && |
|
88 iDialog.FirstTransactionId() == aTransactionItem.Id()) |
|
89 { |
|
90 iDialog.ChangeState(iStateConfirmed); |
|
91 } |
|
92 aTransactionItem.SendL(params,aResponse,ETrue); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // TEarly::ReceiveL |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void TEarly::ReceiveL (CTransactionItemBase& aTransactionItem, |
|
100 CSIPResponse* aResponse) |
|
101 { |
|
102 if (aResponse->IsErrorResponse()) |
|
103 { |
|
104 if (iDialog.FirstTransactionId() == aTransactionItem.Id()) |
|
105 { |
|
106 iDialog.TerminateForkedDialogs(aTransactionItem.Id()); |
|
107 iDialog.ChangeState(iStateTerminated); |
|
108 } |
|
109 } |
|
110 else // 100-299 response |
|
111 { |
|
112 if (aResponse->ResponseCode() > K100Response) |
|
113 { |
|
114 iDialog.SetRemoteTagL(aResponse->To()); |
|
115 if (aTransactionItem.TargetRefresh()) |
|
116 { |
|
117 // Only the final response to the initial transaction |
|
118 // updates the route-set |
|
119 if (aResponse->Type() == CSIPResponse::E2XX && |
|
120 iDialog.FirstTransactionId() == aTransactionItem.Id()) |
|
121 { |
|
122 iDialog.SetRouteSetUsingRecordRouteL( |
|
123 *aResponse, ETrue, KErrSIPInvalidDialogResponse); |
|
124 } |
|
125 iDialog.SetRemoteTargetWithMsgL(*aResponse); |
|
126 } |
|
127 } |
|
128 |
|
129 if (aResponse->Type() == CSIPResponse::E2XX) |
|
130 { |
|
131 if (aTransactionItem.OverlappingRestricted()) |
|
132 { |
|
133 aTransactionItem.SetOverlappingRestricted(EFalse); |
|
134 } |
|
135 if (iDialog.FirstTransactionId() == aTransactionItem.Id()) |
|
136 { |
|
137 iDialog.ChangeState(iStateConfirmed); |
|
138 } |
|
139 } |
|
140 } |
|
141 PassToOwnerL(aTransactionItem,aResponse); |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // TEarly::ReceiveL |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 void TEarly::ReceiveL (TTransactionId aTransactionId, |
|
149 CSIPRequest* aRequest) |
|
150 { |
|
151 CSIPFromHeader* from = aRequest->From(); |
|
152 __SIP_ASSERT_LEAVE (from != 0, KErrArgument); |
|
153 if (iDialog.RemoteTagSet()) |
|
154 { |
|
155 RStringF tagParamName = SIPStrings::StringF(SipStrConsts::ETag); |
|
156 __ASSERT_ALWAYS(iDialog.RemoteTag() == from->ParamValue(tagParamName), |
|
157 User::Leave(KErrSIPInvalidDialogRequest)); |
|
158 } |
|
159 else |
|
160 { |
|
161 iDialog.SetRemoteTagL(aRequest->From()); |
|
162 } |
|
163 CSIPCSeqHeader* cseq = aRequest->CSeq(); |
|
164 __SIP_ASSERT_LEAVE (cseq != 0, KErrArgument); |
|
165 iDialog.SetRemoteSeqNum(cseq->Seq()); |
|
166 PassToOwnerL(aTransactionId,aRequest); |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // TEarly::EndTransaction |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void TEarly::EndTransaction (CTransactionItemBase& aTransactionItem, |
|
174 TInt aReason) |
|
175 { |
|
176 if (aReason) |
|
177 { |
|
178 PassToOwner(aTransactionItem,aReason); |
|
179 } |
|
180 if (iDialog.FirstTransactionId() == aTransactionItem.Id()) |
|
181 { |
|
182 iDialog.SelfDestruct(); |
|
183 } |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // TEarly::GetState |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void TEarly::GetState (CSIPInternalStates::TState& aState) |
|
191 { |
|
192 aState = CSIPInternalStates::EDialogEarly; |
|
193 } |