|
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 : CancelUAS.cpp |
|
15 // Part of : TransactionUser |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "siperr.h" |
|
22 #include "SipAssert.h" |
|
23 #include "siptoheader.h" |
|
24 #include "siprequest.h" |
|
25 #include "sipresponse.h" |
|
26 #include "sipstrings.h" |
|
27 #include "sipstrconsts.h" |
|
28 |
|
29 #include "CancelUAS.h" |
|
30 #include "InviteUAS.h" |
|
31 #include "CTransactionStore.h" |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CCancelUAS::NewL |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CCancelUAS* CCancelUAS::NewL(CUserAgentCreateParams& aParams, |
|
38 MSipConnectionMgr& aConnectionMgr, |
|
39 MSIPRequestRouter& aRouter, |
|
40 MSipDialogs& aDialogs) |
|
41 { |
|
42 CCancelUAS* self = new (ELeave) CCancelUAS(aParams, aDialogs, aRouter); |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(aConnectionMgr); |
|
45 CleanupStack::Pop(self); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CCancelUAS::CCancelUAS |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CCancelUAS::CCancelUAS(CUserAgentCreateParams& aParams, |
|
54 MSipDialogs& aDialogs, |
|
55 MSIPRequestRouter& aRouter) : |
|
56 CNormalUAS(aParams, aDialogs, aRouter) |
|
57 { |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CCancelUAS::ConstructL |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CCancelUAS::ConstructL(MSipConnectionMgr& aConnectionMgr) |
|
65 { |
|
66 CUserAgent::ConstructL(aConnectionMgr); |
|
67 CreateTransactionL(); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CCancelUAS::CancelReceivedL |
|
72 // Can't cancel ACK or CANCEL. Send 200 to CANCEL before 487 to INVITE. If |
|
73 // INVITE UAS has no To tag yet, the To tags of 200 and 487 will differ. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CCancelUAS::CancelReceivedL(CSIPRequest* aCancel, |
|
77 const CUserAgentState& aFinalRespSent) |
|
78 { |
|
79 __SIP_ASSERT_LEAVE(aCancel, KErrArgument); |
|
80 |
|
81 if (!UpdateTransportProtocol(*aCancel)) |
|
82 { |
|
83 // Drop the broken CANCEL |
|
84 delete aCancel; |
|
85 Stop(KErrNone); |
|
86 return; |
|
87 } |
|
88 |
|
89 StoreToTag(*aCancel); |
|
90 |
|
91 TInt responseCode = 0; |
|
92 RStringF reasonPhrase; |
|
93 if (CheckReceivedRequest(*aCancel, responseCode, reasonPhrase)) |
|
94 { |
|
95 CUserAgentServer* uas = |
|
96 iTransactionStore.SearchUasToCancel(*aCancel, *this); |
|
97 if (uas) |
|
98 { |
|
99 iTransportParams = uas->TransportParams(); |
|
100 RStringF method = |
|
101 iTransactionStore.RequestMethod(uas->TransactionId()); |
|
102 |
|
103 if (method == SIPStrings::StringF(SipStrConsts::EAck) || |
|
104 method == SIPStrings::StringF(SipStrConsts::ECancel)) |
|
105 { |
|
106 SendErrorResponseL(400, |
|
107 SIPStrings::StringF(SipStrConsts::EPhraseBadRequest), |
|
108 aFinalRespSent); |
|
109 } |
|
110 else |
|
111 { |
|
112 Send200L(aFinalRespSent, uas->ToTag()); |
|
113 // If INVITE UAS has sent 2xx, it no longer has transaction |
|
114 if (method == SIPStrings::StringF(SipStrConsts::EInvite)) |
|
115 { |
|
116 CInviteUAS::Ptr(*uas).CancelInviteL(); |
|
117 } |
|
118 } |
|
119 } |
|
120 else |
|
121 { |
|
122 SendErrorResponseL(481, |
|
123 SIPStrings::StringF( |
|
124 SipStrConsts::EPhraseCallTransactionDoesNotExist), |
|
125 aFinalRespSent); |
|
126 } |
|
127 } |
|
128 else |
|
129 { |
|
130 __SIP_ASSERT_LEAVE(responseCode >= 300 && responseCode < 700, |
|
131 KErrSIPMalformedMessage); |
|
132 |
|
133 SendErrorResponseL(responseCode, reasonPhrase, aFinalRespSent); |
|
134 } |
|
135 |
|
136 delete aCancel; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CCancelUAS::Send200L |
|
141 // If the canceled transaction has a To-tag, it's put in the response to CANCEL |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void CCancelUAS::Send200L(const CUserAgentState& aFinalRespSent, |
|
145 RStringF aToTag) |
|
146 { |
|
147 CSIPResponse* resp = |
|
148 CSIPResponse::NewLC(200, SIPStrings::StringF(SipStrConsts::EPhraseOk)); |
|
149 FillResponseL(*resp); |
|
150 |
|
151 if (aToTag.DesC().Length() > 0) |
|
152 { |
|
153 CSIPToHeader* to = resp->To(); |
|
154 __SIP_ASSERT_LEAVE(to != NULL, KErrSIPMalformedMessage); |
|
155 |
|
156 to->SetParamL(SIPStrings::StringF(SipStrConsts::ETag), aToTag); |
|
157 } |
|
158 |
|
159 ChangeState(aFinalRespSent); |
|
160 SendResponseToTransactionL(resp); |
|
161 CleanupStack::Pop(resp); |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CCancelUAS::Ptr |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 CCancelUAS& CCancelUAS::Ptr(CUserAgent& aUserAgent) |
|
169 { |
|
170 return static_cast<CCancelUAS&>(aUserAgent); |
|
171 } |