|
1 // Copyright (c) 2007-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 : CSIPResponseUtility.cpp |
|
15 // Part of : Registration |
|
16 // Version : SIP/6.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "CSIPResponseUtility.h" |
|
23 #include "sipresponse.h" |
|
24 #include "uricontainer.h" |
|
25 #include "sipuri.h" |
|
26 #include "siphostport.h" |
|
27 #include "sipaddress.h" |
|
28 #include "siptoheader.h" |
|
29 #include "sipcontactheader.h" |
|
30 #include "sipcallidheader.h" |
|
31 #include "sipcseqheader.h" |
|
32 #include "sipexpiresheader.h" |
|
33 #include "sipviaheader.h" |
|
34 #include "mregistrationcontext.h" |
|
35 #include "SipAssert.h" |
|
36 #include "siperr.h" |
|
37 #include "sipstrings.h" |
|
38 #include "sipstrconsts.h" |
|
39 |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CSIPResponseUtility::IsError |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 TBool CSIPResponseUtility::IsError(CSIPResponse& aSIPResponse) |
|
46 { |
|
47 return (aSIPResponse.IsErrorResponse()); |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CSIPResponseUtility::ContactHeader |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CSIPContactHeader* CSIPResponseUtility::ContactHeader( |
|
55 CSIPContactHeader& aContactInBinding, |
|
56 CSIPResponse& aResponse) |
|
57 { |
|
58 TSglQueIter<CSIPHeaderBase> contact = |
|
59 aResponse.Headers(SIPStrings::StringF(SipStrConsts::EContactHeader)); |
|
60 |
|
61 if (aResponse.HeaderCount( |
|
62 SIPStrings::StringF(SipStrConsts::EContactHeader)) == 1) |
|
63 { |
|
64 return static_cast<CSIPContactHeader*>(contact++); |
|
65 } |
|
66 |
|
67 for (CSIPHeaderBase* header = contact++; header; header = contact++) |
|
68 { |
|
69 CSIPContactHeader* contactHeader = |
|
70 static_cast<CSIPContactHeader*>(header); |
|
71 |
|
72 if (contactHeader->SIPAddress() && |
|
73 contactHeader->SIPAddress()->URI().IsSIPURI() && |
|
74 aContactInBinding.SIPAddress()->URI().IsSIPURI()) |
|
75 { |
|
76 if (contactHeader->SIPAddress()->URI().SIPURI()->User() == |
|
77 aContactInBinding.SIPAddress()->URI().SIPURI()->User()) |
|
78 { |
|
79 return contactHeader; |
|
80 } |
|
81 } |
|
82 else |
|
83 { |
|
84 if (contactHeader->SIPAddress() && |
|
85 contactHeader->SIPAddress()->URI() == |
|
86 aContactInBinding.SIPAddress()->URI()) |
|
87 { |
|
88 return contactHeader; |
|
89 } |
|
90 } |
|
91 } |
|
92 |
|
93 return NULL; |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CSIPResponseUtility::CallIdL |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 HBufC8* CSIPResponseUtility::CallIdL(CSIPResponse& aSIPResponse) |
|
101 { |
|
102 CSIPCallIDHeader* callId = aSIPResponse.CallID(); |
|
103 |
|
104 // panic if there is no CallId header in response |
|
105 __SIP_ASSERT_LEAVE (callId, KErrArgument); |
|
106 |
|
107 return (callId->ToTextValueL()); |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CSIPResponseUtility::CSeqValueL |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 TUint CSIPResponseUtility::CSeqValueL(CSIPResponse& aSIPResponse) |
|
115 { |
|
116 CSIPCSeqHeader* cseq = aSIPResponse.CSeq(); |
|
117 |
|
118 // panic if there is no CSeq header in response |
|
119 __SIP_ASSERT_LEAVE (cseq, KErrArgument); |
|
120 |
|
121 return cseq->Seq(); |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CSIPResponseUtility::ExpireValueL |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 TUint CSIPResponseUtility::ExpireValueL(CSIPContactHeader& aBindingContact, |
|
129 CSIPResponse& aResponse) |
|
130 { |
|
131 const RStringF KExpiresHeaderName = |
|
132 SIPStrings::StringF(SipStrConsts::EExpiresHeader); |
|
133 TUint returnValue = 0; |
|
134 |
|
135 // get Contact header from response |
|
136 CSIPContactHeader* responseContact = |
|
137 ContactHeader(aBindingContact, aResponse); |
|
138 |
|
139 if (responseContact) |
|
140 { |
|
141 if (responseContact->ExpiresParameter() < 0) |
|
142 { |
|
143 if (aResponse.HasHeader(KExpiresHeaderName)) |
|
144 { |
|
145 // copy the expires value from expires header to |
|
146 // expires parameter in contact, remove the expires header |
|
147 CSIPExpiresHeader* expiresHeader = |
|
148 static_cast<CSIPExpiresHeader*>( |
|
149 aResponse.Header(KExpiresHeaderName,0)); |
|
150 |
|
151 responseContact->SetExpiresParameterL( |
|
152 expiresHeader->Value()); |
|
153 |
|
154 if (aResponse.RemoveHeader(expiresHeader) == KErrNone) |
|
155 { |
|
156 delete expiresHeader; expiresHeader = 0; |
|
157 } |
|
158 } |
|
159 else |
|
160 { |
|
161 // copy the expires parameter from binding |
|
162 responseContact->SetExpiresParameterL( |
|
163 aBindingContact.ExpiresParameter()); |
|
164 } |
|
165 } |
|
166 // if expires parameter is not zero and expires parameter in binding |
|
167 // less than expires parameter in response, change expires parameter |
|
168 // in response to lower value |
|
169 if (aBindingContact.ExpiresParameter() != 0 && |
|
170 (aBindingContact.ExpiresParameter() < |
|
171 responseContact->ExpiresParameter())) |
|
172 { |
|
173 responseContact->SetExpiresParameterL( |
|
174 aBindingContact.ExpiresParameter()); |
|
175 } |
|
176 |
|
177 returnValue = responseContact->ExpiresParameter(); |
|
178 } |
|
179 |
|
180 return returnValue; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CSIPResponseUtility::Check2XXResponse |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 TInt CSIPResponseUtility::Check2XXResponse(MRegistrationContext& aRegistration, |
|
188 CSIPResponse& aResponse) |
|
189 { |
|
190 TInt err = KErrNone; |
|
191 const RStringF KContactHeaderName = |
|
192 SIPStrings::StringF(SipStrConsts::EContactHeader); |
|
193 // error if there is no contact header in response |
|
194 if (!aResponse.HasHeader(KContactHeaderName)) |
|
195 { |
|
196 return KErrSIPInvalidRegistrarResponse; |
|
197 } |
|
198 // error if contact header sip address in response is different as contact |
|
199 // header sip address in response |
|
200 if (!ContactHeader(aRegistration.Contact(),aResponse)) |
|
201 { |
|
202 return KErrSIPInvalidRegistrarResponse; |
|
203 } |
|
204 // if there is no expires parameter or expires header in response, |
|
205 // copy te expires parameter from binding. |
|
206 // error if the expires parameter is 0 in response. |
|
207 TUint expireValue = 0; |
|
208 TRAP(err, expireValue = ExpireValueL(aRegistration.Contact(),aResponse)) |
|
209 if (err) |
|
210 { |
|
211 return err; |
|
212 } |
|
213 if (expireValue == 0) |
|
214 { |
|
215 return KErrSIPInvalidRegistrarResponse; |
|
216 } |
|
217 // Invalid Service-Route must be indicated to SIP Profile Agent |
|
218 // as a transport failure. This will lead to a new registration. |
|
219 if (!aRegistration.ServiceRouteOk(aResponse)) |
|
220 { |
|
221 return KErrSIPTransportFailure; |
|
222 } |
|
223 |
|
224 const CURIContainer& uriOfToInBinding = |
|
225 aRegistration.AOR().SIPAddress().URI(); |
|
226 |
|
227 CURIContainer& uriOfToInResponse = |
|
228 aResponse.To()->SIPAddress().URI(); |
|
229 |
|
230 if (!(uriOfToInBinding == uriOfToInResponse)) |
|
231 { |
|
232 err = KErrSIPInvalidRegistrarResponse; |
|
233 } |
|
234 return err; |
|
235 } |