|
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 : csipregistered.cpp |
|
15 // Part of : SIP Registration |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "csipregistered.h" |
|
22 #include "csip423responsereceived.h" |
|
23 #include "SipAssert.h" |
|
24 #include "siprequest.h" |
|
25 #include "sipresponse.h" |
|
26 #include "sipminexpiresheader.h" |
|
27 #include "CSIPResponseUtility.h" |
|
28 #include "MRegistrationOwner.h" |
|
29 #include "sipstrings.h" |
|
30 #include "sipstrconsts.h" |
|
31 #include "siperr.h" |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CSIPRegistered::NewL |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CSIPRegistered* CSIPRegistered::NewL(MRegistrationContext& aRegistration) |
|
38 { |
|
39 CSIPRegistered* self = CSIPRegistered::NewLC(aRegistration); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CSIPRegistered::NewLC |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CSIPRegistered* CSIPRegistered::NewLC(MRegistrationContext& aRegistration) |
|
49 { |
|
50 CSIPRegistered* self = new (ELeave) CSIPRegistered(aRegistration); |
|
51 CleanupStack::PushL(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CSIPRegistered::SetNeighbourStates |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 void CSIPRegistered::SetNeighbourStates( |
|
60 CSIPRegistrationState* aUpdating, |
|
61 CSIPRegistrationState* aUnregistering, |
|
62 CSIPRegistrationState* aUnregistered, |
|
63 CSIPRegistrationState* aResponse423Received) |
|
64 { |
|
65 __SIP_ASSERT_RETURN(aUpdating, KErrArgument); |
|
66 __SIP_ASSERT_RETURN(aUnregistering, KErrArgument); |
|
67 __SIP_ASSERT_RETURN(aUnregistered, KErrArgument); |
|
68 __SIP_ASSERT_RETURN(aResponse423Received, KErrArgument); |
|
69 |
|
70 iUpdating = aUpdating; |
|
71 iUnregistering = aUnregistering; |
|
72 iUnregistered = aUnregistered; |
|
73 iResponse423Received = aResponse423Received; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CSIPRegistered::~CSIPRegistered |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CSIPRegistered::~CSIPRegistered() |
|
81 { |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CSIPRegistered::UpdateL |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 void CSIPRegistered::UpdateL(TTransactionId& aTransactionId, |
|
89 CSIPRequest* aRequest) |
|
90 { |
|
91 __SIP_ASSERT_LEAVE(aRequest, KErrArgument); |
|
92 |
|
93 iRegistration.ChangeState(iUpdating); |
|
94 iRegistration.CurrentState().UpdateL(aTransactionId, aRequest); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CSIPRegistered::UnregisterL |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 void CSIPRegistered::UnregisterL(TTransactionId& aTransactionId, |
|
102 CSIPRequest* aRequest) |
|
103 { |
|
104 __SIP_ASSERT_LEAVE(aRequest, KErrArgument); |
|
105 |
|
106 iRegistration.ChangeState(iUnregistering); |
|
107 iRegistration.CurrentState().UnregisterL(aTransactionId, aRequest); |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CSIPRegistered::ReceiveL |
|
112 // |
|
113 // this function is called when subsequent refresh response is received |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void CSIPRegistered::ReceiveL(TTransactionId aTransactionId, |
|
117 CSIPResponse* aResponse) |
|
118 { |
|
119 __SIP_ASSERT_LEAVE(aResponse, KErrArgument); |
|
120 |
|
121 if (aResponse->Type() == CSIPResponse::E2XX) // 200-299 |
|
122 { |
|
123 if (!iRegistration.ServiceRouteOk(*aResponse)) |
|
124 { |
|
125 iRegistration.ReceivedErrorResponseL(); |
|
126 User::LeaveIfError( |
|
127 PassErrorToOwner(KErrSIPTransportFailure,aTransactionId, |
|
128 iRegistration.RegistrationId())); |
|
129 delete aResponse; |
|
130 iRegistration.SelfDetach(ETrue); |
|
131 iRegistration.ChangeState(iUnregistered); |
|
132 return; |
|
133 } |
|
134 iRegistration.SetRouteHeaderFromResponseL(*aResponse); |
|
135 iRegistration.Received2XXResponseL(*aResponse,aTransactionId); |
|
136 if (iRegistration.Request()) |
|
137 { |
|
138 iRegistration.Request()->DeleteHeaders( |
|
139 SIPStrings::StringF(SipStrConsts::ERouteHeader)); |
|
140 } |
|
141 |
|
142 // don't forward subsequent 2xx response to owner |
|
143 delete aResponse; |
|
144 } |
|
145 else if (aResponse->IsErrorResponse()) // 300- |
|
146 { |
|
147 const RStringF KMinExpiresHeaderName = |
|
148 SIPStrings::StringF(SipStrConsts::EMinExpiresHeader); |
|
149 |
|
150 if (aResponse->ResponseCode() == K423Response && |
|
151 aResponse->HasHeader(KMinExpiresHeaderName)) |
|
152 { |
|
153 iRegistration.Received423ResponseL(*aResponse); |
|
154 iRegistration.ChangeState(iResponse423Received); |
|
155 static_cast<CSIP423ResponseReceived*>(iResponse423Received)-> |
|
156 SetUpdate(ETrue); |
|
157 iRegistration.CurrentState().RegisterL( |
|
158 aTransactionId,iRegistration.Request(),NULL); |
|
159 delete aResponse; |
|
160 } |
|
161 // this happens when error response received from subsequent register. |
|
162 else |
|
163 { |
|
164 // ReceivedErrorResponseL, remove binding |
|
165 iRegistration.ReceivedErrorResponseL(); |
|
166 // pass response to owner |
|
167 PassResponseToOwnerL(aResponse, aTransactionId, |
|
168 iRegistration.RegistrationId()); |
|
169 iRegistration.SelfDetach(ETrue); |
|
170 iRegistration.ChangeState(iUnregistered); |
|
171 } |
|
172 } |
|
173 else // is provisional response 100-199 |
|
174 { |
|
175 // do not forward subsequent 1xx response to owner |
|
176 delete aResponse; |
|
177 } |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CSIPRegistered::TransactionEnded |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 TInt CSIPRegistered::TransactionEnded(TTransactionId aTransactionId, |
|
185 TInt aReason) |
|
186 { |
|
187 if (aReason != KErrNone) |
|
188 { |
|
189 iRegistration.ChangeState(iUnregistered); |
|
190 } |
|
191 // pass error to owner. |
|
192 return (PassErrorToOwner(aReason, aTransactionId, |
|
193 iRegistration.RegistrationId())); |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CSIPRegistered::CSIPRegistered |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 CSIPRegistered::CSIPRegistered(MRegistrationContext& aRegistration) |
|
201 : CSIPRegistrationState (aRegistration) |
|
202 { |
|
203 } |