|
1 // Copyright (c) 2004-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 : compressinglogic.cpp |
|
15 // Part of : SIP SigComp Controller |
|
16 // Version : SIP/3.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <in_sock.h> |
|
23 #include "compressinglogic.h" |
|
24 #include "sipmessage.h" |
|
25 #include "sipresponse.h" |
|
26 #include "siprequest.h" |
|
27 #include "siphostport.h" |
|
28 #include "sipviaheader.h" |
|
29 #include "sipuri.h" |
|
30 #include "siprouteheader.h" |
|
31 #include "sipaddress.h" |
|
32 #include "msiGcompowner.h" |
|
33 #include "sipcontactheader.h" |
|
34 #include "sipheaderbase.h" |
|
35 #include "sipstrings.h" |
|
36 #include "sipstrconsts.h" |
|
37 #include "uricontainer.h" |
|
38 #include "TSIPTransportParams.h" |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CSigCompCompressingLogic::NewL |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CSigCompCompressingLogic* CSigCompCompressingLogic::NewL( |
|
45 MSigCompOwner& aSigCompOwner ) |
|
46 { |
|
47 CSigCompCompressingLogic* self = NewLC( aSigCompOwner ); |
|
48 CleanupStack::Pop(); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CSigCompCompressingLogic::NewLC |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CSigCompCompressingLogic* CSigCompCompressingLogic::NewLC( |
|
57 MSigCompOwner& aSigCompOwner ) |
|
58 { |
|
59 CSigCompCompressingLogic* self = |
|
60 new (ELeave) CSigCompCompressingLogic( aSigCompOwner ); |
|
61 CleanupStack::PushL( self ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CSigCompCompressingLogic::EncodeL |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CBufBase* CSigCompCompressingLogic::EncodeL( |
|
70 const TSIPTransportParams& aTransportParams, |
|
71 CSIPRequest& aRequest, |
|
72 const TInetAddr& aAddress, |
|
73 TBool aStreambasedProtocol, |
|
74 TBool& aCompressed ) |
|
75 { |
|
76 if ( ShouldBeCompressL( aTransportParams, aRequest ) ) |
|
77 { |
|
78 AddSigCompToContactsL( aRequest ); |
|
79 aCompressed = ETrue; |
|
80 SetCompToTopViaL( aRequest ); |
|
81 |
|
82 return iSigCompOwner.EncodeSipAndCompressL( aTransportParams, |
|
83 aRequest, |
|
84 aAddress, |
|
85 aStreambasedProtocol ); |
|
86 } |
|
87 else |
|
88 { |
|
89 aCompressed = EFalse; |
|
90 return iSigCompOwner.EncodeSipL( aRequest, aStreambasedProtocol ); |
|
91 } |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CSigCompCompressingLogic::EncodeL |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 CBufBase* CSigCompCompressingLogic::EncodeL( |
|
99 const TSIPTransportParams& aTransportParams, |
|
100 CSIPResponse& aResponse, |
|
101 const TInetAddr& aAddress, |
|
102 TBool aStreambasedProtocol, |
|
103 TBool& aCompressed ) |
|
104 { |
|
105 if ( ShouldBeCompressL( aResponse ) ) |
|
106 { |
|
107 AddSigCompToContactsL( aResponse ); |
|
108 aCompressed = ETrue; |
|
109 |
|
110 return iSigCompOwner.EncodeSipAndCompressL( aTransportParams, |
|
111 aResponse, |
|
112 aAddress, |
|
113 aStreambasedProtocol ); |
|
114 } |
|
115 else |
|
116 { |
|
117 aCompressed = EFalse; |
|
118 return iSigCompOwner.EncodeSipL( aResponse, aStreambasedProtocol ); |
|
119 } |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // Destructor |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 CSigCompCompressingLogic::~CSigCompCompressingLogic() |
|
127 { |
|
128 |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // Constructor |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 CSigCompCompressingLogic::CSigCompCompressingLogic( MSigCompOwner& aSigCompOwner ) |
|
136 : iSigCompOwner( aSigCompOwner ) |
|
137 { |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CSigCompCompressingLogic::CompInVia |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 TBool CSigCompCompressingLogic::CompInVia( CSIPMessage& aMessage ) |
|
145 { |
|
146 CSIPViaHeader* viaheader; |
|
147 viaheader = TopViaHeader( aMessage ); |
|
148 if ( viaheader ) |
|
149 { |
|
150 if ( viaheader->HasParam( SIPStrings::StringF( SipStrConsts::EComp ) ) ) |
|
151 { |
|
152 if ( viaheader->ParamValue( |
|
153 SIPStrings::StringF( SipStrConsts::EComp ) ) == |
|
154 SIPStrings::StringF( SipStrConsts::ESigComp ) ) |
|
155 { |
|
156 return ETrue; |
|
157 } |
|
158 } |
|
159 } |
|
160 return EFalse; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CSigCompCompressingLogic::SetCompToTopVia |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CSigCompCompressingLogic::SetCompToTopViaL( CSIPMessage& aMessage ) |
|
168 { |
|
169 if ( !CompInVia( aMessage ) ) |
|
170 { |
|
171 CSIPViaHeader* viaheader = TopViaHeader( aMessage ); |
|
172 if ( viaheader ) |
|
173 { |
|
174 viaheader->SetParamL( SIPStrings::StringF( SipStrConsts::EComp ), |
|
175 SIPStrings::StringF( SipStrConsts::ESigComp ) ); |
|
176 } |
|
177 } |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // CSigCompCompressingLogic::DeleteCompFromTopVia |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CSigCompCompressingLogic::DeleteCompFromTopVia( CSIPMessage& aMessage ) |
|
185 { |
|
186 if ( CompInVia( aMessage ) ) |
|
187 { |
|
188 CSIPViaHeader* viaheader = TopViaHeader( aMessage ); |
|
189 viaheader->DeleteParam( SIPStrings::StringF( SipStrConsts::EComp ) ); |
|
190 } |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CSigCompCompressingLogic::TopViaHeader |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 CSIPViaHeader* CSigCompCompressingLogic::TopViaHeader( CSIPMessage& aMessage ) |
|
198 { |
|
199 if ( aMessage.HasHeader( |
|
200 SIPStrings::StringF( SipStrConsts::EViaHeader ) ) ) |
|
201 { |
|
202 TSglQueIter<CSIPHeaderBase> iter = |
|
203 aMessage.Headers( SIPStrings::StringF( SipStrConsts::EViaHeader ) ); |
|
204 CSIPHeaderBase* header = iter; |
|
205 return static_cast<CSIPViaHeader*>( header ); |
|
206 } |
|
207 |
|
208 return 0; |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CSigCompCompressingLogic::HasSigCompParam |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 TBool CSigCompCompressingLogic::HasSigCompParam( CSIPURI& aURI ) const |
|
216 { |
|
217 if ( aURI.HasParam( SIPStrings::StringF( SipStrConsts::EComp ) ) ) |
|
218 { |
|
219 return aURI.ParamValue( SIPStrings::StringF( SipStrConsts::EComp ) ) == |
|
220 SIPStrings::StringF( SipStrConsts::ESigComp ); |
|
221 } |
|
222 return EFalse; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CSigCompCompressingLogic::SetCompEqualSigCompL |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 void CSigCompCompressingLogic::SetCompEqualSigCompL( CSIPURI& aURI ) |
|
230 { |
|
231 if ( !HasSigCompParam( aURI ) ) |
|
232 { |
|
233 aURI.SetParamL( SIPStrings::StringF( SipStrConsts::EComp ), |
|
234 SIPStrings::StringF( SipStrConsts::ESigComp ) ); |
|
235 } |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CSigCompCompressingLogic::RemoveCompEqualSigComp |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 void CSigCompCompressingLogic::RemoveCompEqualSigComp( CSIPURI& aURI ) |
|
243 { |
|
244 aURI.DeleteParam( SIPStrings::StringF( SipStrConsts::EComp ) ); |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CSigCompCompressingLogic::SipUri |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 CSIPURI* CSigCompCompressingLogic::SigCompUriFromRequest( CSIPRequest& aRequest ) |
|
252 { |
|
253 if ( aRequest.HasHeader( |
|
254 SIPStrings::StringF( SipStrConsts::ERouteHeader ) ) ) |
|
255 { |
|
256 TSglQueIter<CSIPHeaderBase> iter = |
|
257 aRequest.Headers(SIPStrings::StringF( SipStrConsts::ERouteHeader ) ); |
|
258 |
|
259 CSIPHeaderBase* header = iter; |
|
260 CSIPRouteHeader* routeheader = static_cast<CSIPRouteHeader*>( header ); |
|
261 |
|
262 if ( routeheader->SIPAddress().URI().IsSIPURI() && |
|
263 routeheader->SIPAddress().URI().SIPURI()->HasParam( |
|
264 SIPStrings::StringF( SipStrConsts::ELr ) ) ) |
|
265 { |
|
266 CSIPURI* sipuri = routeheader->SIPAddress().URI().SIPURI(); |
|
267 if ( HasSigCompParam( *sipuri ) ) |
|
268 { |
|
269 return sipuri; |
|
270 } |
|
271 else |
|
272 { |
|
273 return 0; |
|
274 } |
|
275 } |
|
276 } |
|
277 |
|
278 if ( aRequest.RequestURI()->IsSIPURI() && |
|
279 HasSigCompParam( *aRequest.RequestURI()->SIPURI() ) ) |
|
280 { |
|
281 return aRequest.RequestURI()->SIPURI(); |
|
282 } |
|
283 return 0; |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CSigCompCompressingLogic::ShouldBeCompressL |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 TBool CSigCompCompressingLogic::ShouldBeCompressL( |
|
291 const TSIPTransportParams& aTransportParams, |
|
292 CSIPRequest& aRequest ) |
|
293 { |
|
294 if ( iSigCompOwner.HasCompartmentUser( aTransportParams ) ) |
|
295 { |
|
296 return ETrue; |
|
297 } |
|
298 |
|
299 DeleteCompFromTopVia( aRequest ); |
|
300 CSIPURI* sipuri = SigCompUriFromRequest( aRequest ); |
|
301 if ( sipuri ) |
|
302 { |
|
303 RemoveCompEqualSigComp( *sipuri ); |
|
304 } |
|
305 return EFalse; |
|
306 } |
|
307 |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // CSigCompCompressingLogic::ShouldBeCompressL |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 TBool CSigCompCompressingLogic::ShouldBeCompressL( CSIPResponse& aResponse ) |
|
314 { |
|
315 return CompInVia( aResponse ); |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CSigCompCompressingLogic::AddSigCompToContactsL |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 void CSigCompCompressingLogic::AddSigCompToContactsL( CSIPMessage& aMessage ) |
|
323 { |
|
324 CSIPHeaderBase* headerbase; |
|
325 CSIPContactHeader* header; |
|
326 if ( aMessage.HasHeader( |
|
327 SIPStrings::StringF( SipStrConsts::EContactHeader ) ) ) |
|
328 { |
|
329 TSglQueIter<CSIPHeaderBase> headeriter = |
|
330 aMessage.Headers( SIPStrings::StringF( SipStrConsts::EContactHeader ) ); |
|
331 headeriter.SetToFirst(); |
|
332 while ( ( headerbase = headeriter++ ) != NULL ) |
|
333 { |
|
334 header = static_cast<CSIPContactHeader*>( headerbase ); |
|
335 if ( !header->Star() && |
|
336 header->SIPAddress()->URI().IsSIPURI() && |
|
337 iSigCompOwner.Match( |
|
338 header->SIPAddress()->URI().SIPURI()->HostPort().Host() ) ) |
|
339 { |
|
340 SetCompEqualSigCompL( *header->SIPAddress()->URI().SIPURI() ); |
|
341 } |
|
342 } |
|
343 } |
|
344 } |