|
1 /* |
|
2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: helper SIP related methods |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32math.h> |
|
20 #include <uri8.h> |
|
21 #include <uriutils.h> |
|
22 #include <sip.h> |
|
23 #include <sipservertransaction.h> |
|
24 #include <sipclienttransaction.h> |
|
25 #include <sipacceptcontactheader.h> |
|
26 #include <sipcontactheader.h> |
|
27 #include <sipextensionheader.h> |
|
28 #include <siprequestelements.h> |
|
29 #include <sipresponseelements.h> |
|
30 #include <sipmessageelements.h> |
|
31 #include <sipfromheader.h> |
|
32 #include <sipaddress.h> |
|
33 #include <sipstrings.h> |
|
34 #include <sipstrconsts.h> |
|
35 #include <sdpdocument.h> |
|
36 #include <sdpcodecstringconstants.h> |
|
37 #include <sdpcodecstringpool.h> |
|
38 #include <escapeutils.h> |
|
39 |
|
40 #include "muslogger.h" |
|
41 #include "musavacapabilitycontext.h" |
|
42 |
|
43 _LIT8( KMusAssertedIndentity,"P-Asserted-Identity" ); |
|
44 |
|
45 // ---------------------------------------------------------------------------- |
|
46 // |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 RStringF MusAvaCapabilityContext::SDPStringL( TInt aStringIndex ) |
|
50 { |
|
51 return SdpCodecStringPool::StringPoolL(). |
|
52 StringF( aStringIndex, SdpCodecStringPool::StringTableL() ); |
|
53 } |
|
54 |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 RStringF MusAvaCapabilityContext::SDPStringL( const TDesC8& aString ) |
|
61 { |
|
62 return SdpCodecStringPool::StringPoolL().OpenFStringL( aString ); |
|
63 } |
|
64 |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 RStringF MusAvaCapabilityContext::SIPStringL( const TDesC8& aString ) |
|
71 { |
|
72 return SIPStrings::Pool().OpenFStringL( aString ); |
|
73 } |
|
74 |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 // ---------------------------------------------------------------------------- |
|
79 // |
|
80 void MusAvaCapabilityContext::LocalHostL( |
|
81 const CSIPServerTransaction& aRequest, |
|
82 TPtrC8& aLocalHost, |
|
83 RStringF& aHostType ) |
|
84 { |
|
85 RStringPool strPool = SdpCodecStringPool::StringPoolL(); |
|
86 |
|
87 const CUri8& uri = aRequest.RequestElements()->RemoteUri(); |
|
88 |
|
89 aLocalHost.Set( uri.Uri().Extract( EUriHost ) ); |
|
90 |
|
91 if ( UriUtils::HostType( aLocalHost ) == UriUtils::EIPv6Host ) |
|
92 { |
|
93 aHostType = strPool.StringF( SdpCodecStringConstants::EAddressType, |
|
94 SdpCodecStringPool::StringTableL() ); |
|
95 } |
|
96 else |
|
97 { |
|
98 aHostType = strPool.StringF( |
|
99 SdpCodecStringConstants::EAddressTypeIP4, |
|
100 SdpCodecStringPool::StringTableL() ); |
|
101 } |
|
102 } |
|
103 |
|
104 |
|
105 // -------------------------------------------------------------------------- |
|
106 // |
|
107 // -------------------------------------------------------------------------- |
|
108 // |
|
109 CUri8* MusAvaCapabilityContext::ToUriL( const TDesC8& aUri ) |
|
110 { |
|
111 TUriParser8 uri; |
|
112 User::LeaveIfError( uri.Parse( aUri ) ); |
|
113 |
|
114 return CUri8::NewL( uri ); |
|
115 } |
|
116 |
|
117 |
|
118 // -------------------------------------------------------------------------- |
|
119 // |
|
120 // -------------------------------------------------------------------------- |
|
121 // |
|
122 HBufC8* MusAvaCapabilityContext::ToTextL( CSdpDocument& aSdpContent ) |
|
123 { |
|
124 HBufC8* content = NULL; |
|
125 |
|
126 CBufFlat* encBuf = CBufFlat::NewL( KMUSAVAMaxLengthOfSDPMessage ); |
|
127 CleanupStack::PushL( encBuf ); |
|
128 RBufWriteStream writeStream( *encBuf, 0 ); |
|
129 writeStream.PushL(); |
|
130 aSdpContent.EncodeL( writeStream ); |
|
131 CleanupStack::PopAndDestroy();//writeStream |
|
132 |
|
133 content = encBuf->Ptr( 0 ).AllocL(); |
|
134 CleanupStack::PopAndDestroy( encBuf ); |
|
135 |
|
136 return content; |
|
137 } |
|
138 |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 const CSIPMessageElements& MusAvaCapabilityContext::MessageElementsL( |
|
145 const CSIPTransactionBase& aTrx ) |
|
146 { |
|
147 const CSIPMessageElements* message = NULL; |
|
148 |
|
149 if ( aTrx.IsSIPClientTransaction() ) |
|
150 { |
|
151 |
|
152 const CSIPResponseElements* response = |
|
153 static_cast<const CSIPClientTransaction&> |
|
154 ( aTrx ).ResponseElements(); |
|
155 User::LeaveIfError( !response ? KErrGeneral : KErrNone ); |
|
156 |
|
157 message = &response->MessageElements(); |
|
158 } |
|
159 else |
|
160 { |
|
161 const CSIPRequestElements* request = |
|
162 static_cast<const CSIPServerTransaction&>( aTrx ).RequestElements(); |
|
163 User::LeaveIfError( !request ? KErrGeneral : KErrNone ); |
|
164 |
|
165 message = &request->MessageElements(); |
|
166 } |
|
167 |
|
168 return *message; |
|
169 } |
|
170 |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 CSIPAcceptContactHeader* MusAvaCapabilityContext::AcceptContactHeaderLC( |
|
177 RStringF aValue ) |
|
178 { |
|
179 CSIPAcceptContactHeader* header = CSIPAcceptContactHeader::NewLC(); |
|
180 |
|
181 header->SetParamL( aValue ); |
|
182 header->SetParamL( SIPStrings::StringF( SipStrConsts::EExplicit ) ); |
|
183 |
|
184 return header; |
|
185 } |
|
186 |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 const CSIPAcceptContactHeader* MusAvaCapabilityContext::AcceptContactHeaderL( |
|
193 const CSIPTransactionBase& aTrx ) |
|
194 { |
|
195 return static_cast<const CSIPAcceptContactHeader*> |
|
196 ( Header( SIPStrings::StringF( SipStrConsts::EAcceptContactHeader ), |
|
197 MessageElementsL( aTrx ) ) ); |
|
198 } |
|
199 |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 CSIPContactHeader* MusAvaCapabilityContext::ContactHeaderLC( |
|
206 const CUri8& aAddress, |
|
207 RStringF aValue ) |
|
208 { |
|
209 CUri8* uri = CUri8::NewLC( aAddress.Uri() ); |
|
210 |
|
211 /* |
|
212 if ( !uri->Uri().IsPresent( EUriHost ) ) |
|
213 { |
|
214 uri->SetComponentL( |
|
215 SIPStrings::StringF( SipStrConsts::ELocalHost ).DesC(), EUriHost ); |
|
216 } |
|
217 */ |
|
218 |
|
219 CSIPAddress* address = CSIPAddress::NewL( uri ); |
|
220 CleanupStack::Pop( uri ); |
|
221 CleanupStack::PushL( address ); |
|
222 |
|
223 CSIPContactHeader* header = CSIPContactHeader::NewL( address ); |
|
224 CleanupStack::Pop( address ); |
|
225 CleanupStack::PushL( header ); |
|
226 |
|
227 if ( aValue != SIPStrings::StringF( SipStrConsts::EEmpty ) ) |
|
228 { |
|
229 TInt separator = aValue.DesC().Find( KMUSAVASemicolon ); |
|
230 if ( separator < KErrNone ) |
|
231 { |
|
232 header->SetParamL( aValue ); |
|
233 } |
|
234 else |
|
235 { |
|
236 TPtrC8 head = aValue.DesC().Left( separator ); |
|
237 TPtrC8 tail = aValue.DesC().Mid( |
|
238 separator + KMUSAVASemicolon().Length() ); |
|
239 |
|
240 RStringF theHead = SIPStringL( head ); |
|
241 CleanupClosePushL( theHead ); |
|
242 RStringF theTail = SIPStringL( tail ); |
|
243 CleanupClosePushL( theTail ); |
|
244 |
|
245 header->SetParamL( theHead ); |
|
246 header->SetParamL( theTail ); |
|
247 |
|
248 CleanupStack::PopAndDestroy();//theTail |
|
249 CleanupStack::PopAndDestroy();//theHead |
|
250 } |
|
251 } |
|
252 |
|
253 return header; |
|
254 } |
|
255 |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 const CSIPContactHeader* MusAvaCapabilityContext::ContactHeaderL( |
|
262 const CSIPTransactionBase& aTrx ) |
|
263 { |
|
264 return static_cast<const CSIPContactHeader*> |
|
265 ( Header( SIPStrings::StringF( SipStrConsts::EContactHeader ), |
|
266 MessageElementsL( aTrx ) ) ); |
|
267 } |
|
268 |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 CSIPExtensionHeader* MusAvaCapabilityContext::UserAgentHeaderLC( |
|
275 const TDesC8& aValue ) |
|
276 { |
|
277 return CSIPExtensionHeader::NewLC( KMUSAVASIPHeaderUserAgent, aValue ); |
|
278 } |
|
279 |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 const CSIPExtensionHeader* MusAvaCapabilityContext::UserAgentHeaderL( |
|
286 const CSIPTransactionBase& aTrx ) |
|
287 { |
|
288 RStringF userAgentHeaderName = SIPStringL( KMUSAVASIPHeaderUserAgent ); |
|
289 CleanupClosePushL( userAgentHeaderName ); |
|
290 |
|
291 const CSIPExtensionHeader* header = |
|
292 static_cast<const CSIPExtensionHeader*> |
|
293 ( Header( userAgentHeaderName, MessageElementsL( aTrx ) ) ); |
|
294 |
|
295 CleanupStack::PopAndDestroy();//userAgentHeaderName |
|
296 |
|
297 return header; |
|
298 } |
|
299 |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 CSIPExtensionHeader* MusAvaCapabilityContext::PAssertedIdentityHeaderLC( |
|
306 const TDesC8& aValue ) |
|
307 { |
|
308 return CSIPExtensionHeader::NewLC( KMUSAVASIPHeaderPAssertedIdentity, |
|
309 aValue ); |
|
310 } |
|
311 |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 const CUri8& MusAvaCapabilityContext::OriginatorL( |
|
318 const CSIPServerTransaction& aTrx ) |
|
319 { |
|
320 const CSIPRequestElements* request = aTrx.RequestElements(); |
|
321 User::LeaveIfError( !request ? KErrGeneral : KErrNone ); |
|
322 |
|
323 const CSIPFromHeader* from = request->FromHeader(); |
|
324 |
|
325 User::LeaveIfError( from ? KErrNone : KErrGeneral ); |
|
326 |
|
327 return from->SIPAddress().Uri8(); |
|
328 } |
|
329 |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 const CSIPHeaderBase* MusAvaCapabilityContext::Header( |
|
336 RStringF aHeaderName, |
|
337 const CSIPMessageElements& aMessage ) |
|
338 { |
|
339 TBool found = EFalse; |
|
340 CSIPHeaderBase* header = NULL; |
|
341 const RPointerArray<CSIPHeaderBase>& headers = aMessage.UserHeaders(); |
|
342 |
|
343 for ( TInt i=0; i < headers.Count() && !found; i++ ) |
|
344 { |
|
345 header = headers[i]; |
|
346 if ( header->Name() == aHeaderName ) |
|
347 { |
|
348 found = ETrue; |
|
349 } |
|
350 else |
|
351 { |
|
352 header = NULL; |
|
353 } |
|
354 } |
|
355 return header; |
|
356 } |
|
357 |
|
358 |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 const CSIPHeaderBase* MusAvaCapabilityContext::Header( |
|
364 RStringF aHeaderName, |
|
365 const CSIPMessageElements& aMessage, |
|
366 TUint aIndex ) |
|
367 { |
|
368 TInt found = -1; |
|
369 CSIPHeaderBase* header = NULL; |
|
370 const RPointerArray<CSIPHeaderBase>& headers = aMessage.UserHeaders(); |
|
371 |
|
372 for ( TInt i=0; i < headers.Count() && found != aIndex; i++ ) |
|
373 { |
|
374 header = headers[i]; |
|
375 if ( header->Name() == aHeaderName ) |
|
376 { |
|
377 found++; |
|
378 } |
|
379 else |
|
380 { |
|
381 header = NULL; |
|
382 } |
|
383 } |
|
384 return header; |
|
385 } |
|
386 |
|
387 |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 // ----------------------------------------------------------------------------- |
|
391 // |
|
392 TUint MusAvaCapabilityContext::HeaderCount( |
|
393 RStringF aHeaderName, |
|
394 const CSIPMessageElements& aMessage ) |
|
395 { |
|
396 TUint found = 0; |
|
397 CSIPHeaderBase* header = NULL; |
|
398 const RPointerArray<CSIPHeaderBase>& headers = aMessage.UserHeaders(); |
|
399 |
|
400 for ( TInt i=0; i < headers.Count(); i++ ) |
|
401 { |
|
402 header = headers[i]; |
|
403 if ( header->Name() == aHeaderName ) |
|
404 { |
|
405 found++; |
|
406 } |
|
407 } |
|
408 return found; |
|
409 } |
|
410 |
|
411 |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 // ----------------------------------------------------------------------------- |
|
415 // |
|
416 CDesCArrayFlat* MusAvaCapabilityContext::PAssertedIdentityHeaderL( |
|
417 const CSIPMessageElements& aMessage ) |
|
418 { |
|
419 MUS_LOG( "mus: [MUSAVA] -> MusAvaCapabilityContext::PAssertedIdentityHeaderL" ) |
|
420 |
|
421 RStringF p = SIPStrings::Pool().OpenFStringL( KMusAssertedIndentity() ); |
|
422 CleanupClosePushL( p ); |
|
423 TInt headerCount = HeaderCount( p,aMessage); |
|
424 |
|
425 CDesCArrayFlat* headers = new( ELeave ) CDesCArrayFlat( 2 ); |
|
426 CleanupStack::PushL( headers ); |
|
427 |
|
428 for ( TInt i=0; i < headerCount; i++ ) |
|
429 { |
|
430 const CSIPHeaderBase* pAssertedId = |
|
431 MusAvaCapabilityContext::Header( p, aMessage, i ); |
|
432 |
|
433 if ( pAssertedId ) |
|
434 { |
|
435 HBufC8* value = pAssertedId->ToTextValueLC(); |
|
436 CSIPAddress* address = CSIPAddress::DecodeL( *value ); |
|
437 CleanupStack::PushL( address ); |
|
438 const TDesC8& uriInPAssertedId = address->Uri8().Uri().UriDes(); |
|
439 if ( uriInPAssertedId.Length() > 0 ) |
|
440 { |
|
441 HBufC* uriBuf = |
|
442 EscapeUtils::ConvertToUnicodeFromUtf8L( uriInPAssertedId ); |
|
443 CleanupStack::PushL( uriBuf ); |
|
444 headers->AppendL( *uriBuf ); |
|
445 CleanupStack::PopAndDestroy( uriBuf ); |
|
446 } |
|
447 CleanupStack::PopAndDestroy( address ); |
|
448 CleanupStack::PopAndDestroy( value ); |
|
449 } |
|
450 } |
|
451 |
|
452 CleanupStack::Pop( headers ); |
|
453 CleanupStack::PopAndDestroy( &p ); |
|
454 |
|
455 MUS_LOG( "mus: [MUSAVA] <- MusAvaCapabilityContext::PAssertedIdentityHeaderL" ) |
|
456 return headers; |
|
457 } |
|
458 |