|
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 : CSIPOptionsHandler.cpp |
|
15 // Part of : SIP Client Resolver |
|
16 // Version : 1.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include <e32math.h> |
|
22 #include <uri8.h> |
|
23 #include "CSIPOptionsHandler.h" |
|
24 #include "sdpcodecstringconstants.h" |
|
25 #include "sipresponse.h" |
|
26 #include "siprequest.h" |
|
27 #include "uricontainer.h" |
|
28 #include "sipuri.h" |
|
29 #include "siphostport.h" |
|
30 #include "sipcontenttypeheader.h" |
|
31 #include "sipacceptheader.h" |
|
32 #include "sdpdocument.h" |
|
33 #include "sdporiginfield.h" |
|
34 #include "sdpconnectionfield.h" |
|
35 #include "sdpmediafield.h" |
|
36 #include "sdpfmtattributefield.h" |
|
37 #include "siperr.h" |
|
38 #include "sdpcodecstringpool.h" |
|
39 #include "sipstrings.h" |
|
40 #include "sipstrconsts.h" |
|
41 |
|
42 _LIT8(KSdp, "sdp"); |
|
43 _LIT8(KApplication, "application"); |
|
44 _LIT8(KSessionName, "-"); |
|
45 _LIT8(KOriginFieldUser, "-"); |
|
46 |
|
47 const TUint KResponse200 = 200; |
|
48 const TInt KSdpExternalizeBufferExpandSize = 100; |
|
49 |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // CSIPOptionsHandler::NewL |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 CSIPOptionsHandler* CSIPOptionsHandler::NewLC(CSIPRequest& aRequest) |
|
56 { |
|
57 CSIPOptionsHandler* self = new(ELeave)CSIPOptionsHandler; |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(aRequest); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------------------------- |
|
64 // CSIPOptionsHandler::CSIPOptionsHandler |
|
65 // ---------------------------------------------------------------------------- |
|
66 // |
|
67 CSIPOptionsHandler::CSIPOptionsHandler() |
|
68 { |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------------------------------- |
|
72 // CSIPOptionsHandler::ConstructL |
|
73 // ---------------------------------------------------------------------------- |
|
74 // |
|
75 void CSIPOptionsHandler::ConstructL(CSIPRequest& aRequest) |
|
76 { |
|
77 RStringPool strPool = SdpCodecStringPool::StringPoolL(); |
|
78 |
|
79 iSdpNetType = strPool.StringF(SdpCodecStringConstants::ENetType, |
|
80 SdpCodecStringPool::StringTableL()); |
|
81 |
|
82 iSdpIPv4Type = strPool.StringF(SdpCodecStringConstants::EAddressTypeIP4, |
|
83 SdpCodecStringPool::StringTableL()); |
|
84 |
|
85 iSdpIPv6Type = strPool.StringF(SdpCodecStringConstants::EAddressType, |
|
86 SdpCodecStringPool::StringTableL()); |
|
87 |
|
88 iRtpAvp = strPool.StringF(SdpCodecStringConstants::EProtocolRtpAvp, |
|
89 SdpCodecStringPool::StringTableL()); |
|
90 |
|
91 iRtpmap = strPool.StringF(SdpCodecStringConstants::EAttributeRtpmap, |
|
92 SdpCodecStringPool::StringTableL()); |
|
93 |
|
94 iApplication = strPool.StringF(SdpCodecStringConstants::EMediaApplication, |
|
95 SdpCodecStringPool::StringTableL()); |
|
96 |
|
97 iSdpAccepted = SDPAccepted(aRequest); |
|
98 // Create SDP document |
|
99 iSdpDocument = CSdpDocument::NewL(); |
|
100 if (iSdpAccepted) |
|
101 { |
|
102 iSdpDocument->SetSessionNameL(KSessionName); |
|
103 // Origin field |
|
104 TPtrC8 localHost; |
|
105 RStringF hostType; |
|
106 LocalHostL(aRequest,localHost,hostType); |
|
107 CSdpOriginField* originField = CreateOriginFieldL(localHost,hostType); |
|
108 iSdpDocument->SetOriginField(originField); |
|
109 // Connection field |
|
110 CSdpConnectionField* connectionField = |
|
111 CSdpConnectionField::NewL(iSdpNetType,hostType,localHost); |
|
112 iSdpDocument->SetConnectionField(connectionField); |
|
113 } |
|
114 } |
|
115 |
|
116 // ---------------------------------------------------------------------------- |
|
117 // CSIPOptionsHandler::~CSIPOptionsHandler |
|
118 // ---------------------------------------------------------------------------- |
|
119 // |
|
120 CSIPOptionsHandler::~CSIPOptionsHandler () |
|
121 { |
|
122 delete iSdpDocument; |
|
123 iSipAcceptHeaders.ResetAndDestroy(); |
|
124 } |
|
125 |
|
126 // ---------------------------------------------------------------------------- |
|
127 // CSIPOptionsHandler::AddClientDataL |
|
128 // ---------------------------------------------------------------------------- |
|
129 // |
|
130 void CSIPOptionsHandler::AddClientDataL(CSdpDocument& aSdpDocument) |
|
131 { |
|
132 RPointerArray<CSdpMediaField>& mediaFields = aSdpDocument.MediaFields(); |
|
133 for (TInt i=0; i < mediaFields.Count(); i++) |
|
134 { |
|
135 CSdpMediaField& newMediaField = *mediaFields[i]; |
|
136 CSdpMediaField* existingField = FindMatchingField(newMediaField); |
|
137 if (!existingField) |
|
138 { |
|
139 CSdpMediaField* clone = newMediaField.CloneL(); |
|
140 CleanupStack::PushL( clone ); |
|
141 AppendMediaFieldL( clone ); |
|
142 CleanupStack::Pop( clone ); |
|
143 } |
|
144 else |
|
145 { |
|
146 AddAttributesL(newMediaField,*existingField); |
|
147 } |
|
148 } |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // CSIPOptionsHandler::AddClientDataL |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 void CSIPOptionsHandler::AddClientDataL( RPointerArray<CSdpMediaField>* |
|
156 aMediaFields) |
|
157 { |
|
158 if ( aMediaFields->Count() > 0 ) |
|
159 { |
|
160 RPointerArray<CSdpMediaField>& mediaFields = *aMediaFields; |
|
161 for (TInt i=0; i < mediaFields.Count(); i++) |
|
162 { |
|
163 CSdpMediaField* existingField = FindMatchingField( *mediaFields[i] ); |
|
164 if ( !existingField ) |
|
165 { |
|
166 AppendMediaFieldL( mediaFields[i] ); |
|
167 aMediaFields->Remove( i ); |
|
168 } |
|
169 else |
|
170 { |
|
171 AddAttributesL( mediaFields[i],*existingField ); |
|
172 } |
|
173 } |
|
174 } |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CSIPOptionsHandler::AppendMediaFieldL |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CSIPOptionsHandler::AppendMediaFieldL( CSdpMediaField* aMediafield ) |
|
182 { |
|
183 aMediafield->SetPortL(0); |
|
184 UpdateFormatListL(*aMediafield); |
|
185 iSdpDocument->MediaFields().AppendL(aMediafield); |
|
186 } |
|
187 |
|
188 // ---------------------------------------------------------------------------- |
|
189 // CSIPOptionsHandler::CreateResponseL |
|
190 // ---------------------------------------------------------------------------- |
|
191 // |
|
192 CSIPResponse* CSIPOptionsHandler::CreateResponseL( RArray<TUid>& aUids, |
|
193 MSipClients& aSipClients, |
|
194 CSIPClientResolver2& aClientResolver2 ) |
|
195 { |
|
196 CSIPResponse* response = |
|
197 CSIPResponse::NewLC(KResponse200, |
|
198 SIPStrings::StringF(SipStrConsts::EPhraseOk)); |
|
199 if (iSdpAccepted) |
|
200 { |
|
201 // Add Content-Type-header |
|
202 CSIPContentTypeHeader* contentType = |
|
203 CSIPContentTypeHeader::NewLC(KApplication,KSdp); |
|
204 response->AddHeaderL(contentType); |
|
205 CleanupStack::Pop(contentType); |
|
206 // Encode and add content |
|
207 CBufFlat* sdpBuf = CBufFlat::NewL(KSdpExternalizeBufferExpandSize); |
|
208 CleanupStack::PushL(sdpBuf); |
|
209 RBufWriteStream writeStream(*sdpBuf,0); |
|
210 writeStream.PushL(); |
|
211 iSdpDocument->EncodeL(writeStream); |
|
212 writeStream.Pop(); |
|
213 writeStream.Close(); |
|
214 TPtr8 encodedSdp = sdpBuf->Ptr(0); |
|
215 response->SetContent(encodedSdp.AllocL()); |
|
216 CleanupStack::PopAndDestroy(sdpBuf); |
|
217 } |
|
218 AddAcceptToResponseL( *response, aUids, aSipClients, aClientResolver2 ); |
|
219 CleanupStack::Pop(response); |
|
220 return response; |
|
221 } |
|
222 |
|
223 // ---------------------------------------------------------------------------- |
|
224 // CSIPOptionsHandler::AddAcceptToResponseL |
|
225 // ---------------------------------------------------------------------------- |
|
226 // |
|
227 void CSIPOptionsHandler::AddAcceptToResponseL( CSIPResponse& aResponse, |
|
228 RArray<TUid>& aUids, |
|
229 MSipClients& aSipClients, |
|
230 CSIPClientResolver2& aClientResolver2 ) |
|
231 { |
|
232 CollectHeadersL( aUids,aSipClients,aClientResolver2 ); |
|
233 RemoveDuplicateAcceptHeaders(); |
|
234 CSIPAcceptHeader* acceptHeader; |
|
235 |
|
236 for ( TInt i=iSipAcceptHeaders.Count()-1;i >= 0;i-- ) |
|
237 { |
|
238 acceptHeader = static_cast<CSIPAcceptHeader*>( iSipAcceptHeaders[ i ] ); |
|
239 if ( acceptHeader->IsEmpty() ) |
|
240 { |
|
241 delete acceptHeader; |
|
242 acceptHeader = NULL; |
|
243 iSipAcceptHeaders.Remove( i ); |
|
244 } |
|
245 else |
|
246 { |
|
247 CSIPHeaderBase* header = iSipAcceptHeaders[i]; |
|
248 aResponse.AddHeaderL( header ); |
|
249 iSipAcceptHeaders.Remove( i ); |
|
250 } |
|
251 } |
|
252 if ( iSipAcceptHeaders.Count() > 0 ) |
|
253 { |
|
254 iSipAcceptHeaders.ResetAndDestroy(); |
|
255 } |
|
256 } |
|
257 |
|
258 // ---------------------------------------------------------------------------- |
|
259 // CSIPOptionsHandler::CollectHeadersL |
|
260 // ---------------------------------------------------------------------------- |
|
261 // |
|
262 void CSIPOptionsHandler::CollectHeadersL( |
|
263 RArray<TUid>& aUids, |
|
264 MSipClients& aSipClients, |
|
265 CSIPClientResolver2& aClientResolver2 ) |
|
266 { |
|
267 for ( TInt i=0; i < aUids.Count(); i++ ) |
|
268 { |
|
269 MSipClient* client = aSipClients.GetByUID( aUids[i] ); |
|
270 if ( client ) |
|
271 { |
|
272 CollectHeadersL( client ); |
|
273 } |
|
274 } |
|
275 for ( TInt i=0; i < aClientResolver2.Clients().Count(); i++ ) |
|
276 { |
|
277 CSIPResolvedClient2* client2 = aClientResolver2.Clients()[i]; |
|
278 if ( client2 ) |
|
279 { |
|
280 CollectHeadersL( client2 ); |
|
281 } |
|
282 } |
|
283 } |
|
284 |
|
285 // ---------------------------------------------------------------------------- |
|
286 // CSIPOptionsHandler::RemoveDuplicateAcceptHeaders |
|
287 // ---------------------------------------------------------------------------- |
|
288 // |
|
289 void CSIPOptionsHandler::RemoveDuplicateAcceptHeaders() |
|
290 { |
|
291 for (TInt i=0;i<iSipAcceptHeaders.Count();i++) |
|
292 { |
|
293 CSIPAcceptHeader* acceptHeader = |
|
294 static_cast<CSIPAcceptHeader*>( iSipAcceptHeaders[ i ] ); |
|
295 |
|
296 for ( TInt j=iSipAcceptHeaders.Count() - 1;j>i;j-- ) |
|
297 { |
|
298 CSIPAcceptHeader* acceptHeaderT = |
|
299 static_cast<CSIPAcceptHeader*> ( iSipAcceptHeaders[ j ] ); |
|
300 |
|
301 if ( ( ( acceptHeader->MediaType().Compare( |
|
302 acceptHeaderT->MediaType()) == 0 ) && |
|
303 ( acceptHeader->MediaSubtype().Compare( |
|
304 acceptHeaderT->MediaSubtype() ) == 0 ) ) ) |
|
305 { |
|
306 delete acceptHeaderT; |
|
307 acceptHeaderT = NULL; |
|
308 iSipAcceptHeaders.Remove( j ); |
|
309 } |
|
310 } |
|
311 } |
|
312 } |
|
313 |
|
314 // ---------------------------------------------------------------------------- |
|
315 // CSIPOptionsHandler::CollectHeadersL |
|
316 // ---------------------------------------------------------------------------- |
|
317 // |
|
318 void CSIPOptionsHandler::CollectHeadersL( MSipClient* aSipClient ) |
|
319 { |
|
320 RPointerArray<CSIPHeaderBase>& headers = aSipClient->SIPHeaders(); |
|
321 |
|
322 for ( TInt i=0; i < headers.Count();i++ ) |
|
323 { |
|
324 if ( headers[i]->Name() == |
|
325 SIPStrings::StringF( SipStrConsts::EAcceptHeader ) ) |
|
326 { |
|
327 CSIPHeaderBase* accept = headers[i]->CloneL(); |
|
328 CleanupStack::PushL( accept ); |
|
329 iSipAcceptHeaders.AppendL( accept ); |
|
330 CleanupStack::Pop( accept ); |
|
331 } |
|
332 } |
|
333 } |
|
334 |
|
335 // ---------------------------------------------------------------------------- |
|
336 // CSIPOptionsHandler::CollectHeadersL |
|
337 // ---------------------------------------------------------------------------- |
|
338 // |
|
339 void CSIPOptionsHandler::CollectHeadersL( CSIPResolvedClient2* aClient ) |
|
340 { |
|
341 RPointerArray<CSIPContentTypeHeader> contentTypes; |
|
342 TRAPD(err, contentTypes = aClient->SupportedContentTypesL()); |
|
343 if ( err == KErrNoMemory ) |
|
344 { |
|
345 User::Leave( err ); |
|
346 } |
|
347 if ( !err ) |
|
348 { |
|
349 CSIPOptionsHandler::PushLC(&contentTypes); |
|
350 for ( TInt i=0; i < contentTypes.Count();i++ ) |
|
351 { |
|
352 HBufC8* text = contentTypes[i]->ToTextValueL(); |
|
353 CleanupStack::PushL( text ); |
|
354 RPointerArray<CSIPAcceptHeader> acceptHeaders; |
|
355 acceptHeaders = CSIPAcceptHeader::DecodeL( *text ); |
|
356 CleanupStack::PopAndDestroy( text ); |
|
357 text = NULL; |
|
358 CSIPOptionsHandler::PushLC(&acceptHeaders); |
|
359 CSIPAcceptHeader* accept = NULL; |
|
360 for (TInt j=0;j < acceptHeaders.Count();j++) |
|
361 { |
|
362 accept = acceptHeaders[j]; |
|
363 iSipAcceptHeaders.AppendL( accept ); |
|
364 acceptHeaders[j] = NULL; |
|
365 } |
|
366 CleanupStack::Pop();//acceptHeaders |
|
367 acceptHeaders.Reset(); |
|
368 } |
|
369 CleanupStack::Pop();//contentTypes |
|
370 contentTypes.ResetAndDestroy(); |
|
371 } |
|
372 } |
|
373 |
|
374 // ----------------------------------------------------------------------------- |
|
375 // CSIPOptionsHandler::PushLC |
|
376 // ----------------------------------------------------------------------------- |
|
377 // |
|
378 void CSIPOptionsHandler::PushLC(RPointerArray<CSIPContentTypeHeader>* aArray) |
|
379 { |
|
380 CleanupStack::PushL(TCleanupItem(ResetAndDestroyArray,aArray)); |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CSIPOptionsHandler::ResetAndDestroyArray |
|
385 // ----------------------------------------------------------------------------- |
|
386 // |
|
387 void CSIPOptionsHandler::ResetAndDestroyArray(TAny* anArray) |
|
388 { |
|
389 RPointerArray<CSIPContentTypeHeader>* array = |
|
390 reinterpret_cast<RPointerArray<CSIPContentTypeHeader>*>(anArray); |
|
391 if (array) |
|
392 { |
|
393 array->ResetAndDestroy(); |
|
394 } |
|
395 } |
|
396 |
|
397 // ----------------------------------------------------------------------------- |
|
398 // CSIPOptionsHandler::PushLC |
|
399 // ----------------------------------------------------------------------------- |
|
400 // |
|
401 void CSIPOptionsHandler::PushLC(RPointerArray<CSIPAcceptHeader>* aArray) |
|
402 { |
|
403 CleanupStack::PushL(TCleanupItem(ResetAndDestroy,aArray)); |
|
404 } |
|
405 |
|
406 // ----------------------------------------------------------------------------- |
|
407 // CSIPOptionsHandler::ResetAndDestroyArray |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 void CSIPOptionsHandler::ResetAndDestroy(TAny* anArray) |
|
411 { |
|
412 RPointerArray<CSIPAcceptHeader>* array = |
|
413 reinterpret_cast<RPointerArray<CSIPAcceptHeader>*>(anArray); |
|
414 if (array) |
|
415 { |
|
416 array->ResetAndDestroy(); |
|
417 } |
|
418 } |
|
419 |
|
420 // ---------------------------------------------------------------------------- |
|
421 // CSIPOptionsHandler::SDPAccepted |
|
422 // ---------------------------------------------------------------------------- |
|
423 // |
|
424 TBool CSIPOptionsHandler::SDPAccepted(CSIPRequest& aRequest) |
|
425 { |
|
426 TSglQueIter<CSIPHeaderBase> iter = |
|
427 aRequest.Headers(SIPStrings::StringF(SipStrConsts::EAcceptHeader)); |
|
428 |
|
429 while (iter) |
|
430 { |
|
431 CSIPHeaderBase* header = iter++; |
|
432 CSIPAcceptHeader* accept = static_cast<CSIPAcceptHeader*>(header); |
|
433 if (accept->MediaType().CompareF(KApplication) == 0 && |
|
434 accept->MediaSubtype().CompareF(KSdp) == 0) |
|
435 { |
|
436 return ETrue; |
|
437 } |
|
438 } |
|
439 |
|
440 return EFalse; |
|
441 } |
|
442 |
|
443 // ---------------------------------------------------------------------------- |
|
444 // CSIPOptionsHandler::FindMatchingField |
|
445 // ---------------------------------------------------------------------------- |
|
446 // |
|
447 CSdpMediaField* CSIPOptionsHandler::FindMatchingField( |
|
448 const CSdpMediaField& aMediaField) |
|
449 { |
|
450 for (TInt i=0; i < iSdpDocument->MediaFields().Count(); i++) |
|
451 { |
|
452 CSdpMediaField* mField = iSdpDocument->MediaFields()[i]; |
|
453 if (mField && |
|
454 aMediaField.Media() == mField->Media() && |
|
455 aMediaField.Protocol() == mField->Protocol()) |
|
456 { |
|
457 if (aMediaField.Media() != iApplication) |
|
458 { |
|
459 // FormatList is compared only for "application" media type |
|
460 return mField; |
|
461 } |
|
462 if (aMediaField.FormatList().CompareF(mField->FormatList()) == 0) |
|
463 { |
|
464 return mField; |
|
465 } |
|
466 } |
|
467 } |
|
468 return NULL; |
|
469 } |
|
470 |
|
471 // ---------------------------------------------------------------------------- |
|
472 // CSIPOptionsHandler::AddAttributesL |
|
473 // ---------------------------------------------------------------------------- |
|
474 // |
|
475 void CSIPOptionsHandler::AddAttributesL( |
|
476 CSdpMediaField& aSource, |
|
477 CSdpMediaField& aDestination) |
|
478 { |
|
479 RPointerArray<CSdpFmtAttributeField> attributes = |
|
480 aSource.FormatAttributeFields(); |
|
481 |
|
482 if (aSource.Protocol() == iRtpAvp && attributes.Count() > 0) |
|
483 { |
|
484 TBool updateFormatList = EFalse; |
|
485 for (TInt i=0; i < attributes.Count(); i++) |
|
486 { |
|
487 CSdpFmtAttributeField* attribute = attributes[i]; |
|
488 if (attribute->Attribute() == iRtpmap && |
|
489 !HasMatchingFmtAttritbute(aDestination,*attribute)) |
|
490 { |
|
491 CSdpFmtAttributeField* clone = attribute->CloneL(); |
|
492 CleanupStack::PushL(clone); |
|
493 updateFormatList = |
|
494 AppendFormatAttributeFieldsL( clone, |
|
495 aDestination ); |
|
496 CleanupStack::Pop(clone); |
|
497 } |
|
498 } |
|
499 if (updateFormatList) |
|
500 { |
|
501 UpdateFormatListL(aDestination); |
|
502 } |
|
503 } |
|
504 } |
|
505 |
|
506 // ---------------------------------------------------------------------------- |
|
507 // CSIPOptionsHandler::AddAttributesL |
|
508 // ---------------------------------------------------------------------------- |
|
509 // |
|
510 void CSIPOptionsHandler::AddAttributesL( |
|
511 CSdpMediaField* aSource, |
|
512 CSdpMediaField& aDestination) |
|
513 { |
|
514 RPointerArray<CSdpFmtAttributeField> attributes = |
|
515 aSource->FormatAttributeFields(); |
|
516 if (aSource->Protocol() == iRtpAvp && attributes.Count() > 0) |
|
517 { |
|
518 TBool updateFormatList = EFalse; |
|
519 for (TInt i=0; i < attributes.Count(); i++) |
|
520 { |
|
521 if (attributes[i]->Attribute() == iRtpmap && |
|
522 !HasMatchingFmtAttritbute(aDestination,*attributes[i])) |
|
523 { |
|
524 updateFormatList =AppendFormatAttributeFieldsL( attributes[i], |
|
525 aDestination ); |
|
526 attributes[i] = NULL; |
|
527 } |
|
528 } |
|
529 if (updateFormatList) |
|
530 { |
|
531 UpdateFormatListL(aDestination); |
|
532 } |
|
533 } |
|
534 } |
|
535 |
|
536 // ---------------------------------------------------------------------------- |
|
537 // CSIPOptionsHandler::AppendFormatAttributeFieldsL |
|
538 // ---------------------------------------------------------------------------- |
|
539 // |
|
540 TBool CSIPOptionsHandler::AppendFormatAttributeFieldsL( |
|
541 CSdpFmtAttributeField* aAttribute, |
|
542 CSdpMediaField& aDestination ) |
|
543 { |
|
544 aDestination.FormatAttributeFields().AppendL(aAttribute); |
|
545 return ETrue; |
|
546 } |
|
547 |
|
548 // ---------------------------------------------------------------------------- |
|
549 // CSIPOptionsHandler::CreateOriginFieldL |
|
550 // ---------------------------------------------------------------------------- |
|
551 // |
|
552 CSdpOriginField* CSIPOptionsHandler::CreateOriginFieldL( |
|
553 const TDesC8& aLocalHost, |
|
554 const RStringF& aHostType) const |
|
555 { |
|
556 TTime now; |
|
557 now.UniversalTime(); |
|
558 TInt64 rand = now.Int64(); |
|
559 TInt64 sessionID = Math::Rand(rand); |
|
560 return CSdpOriginField::NewL(KOriginFieldUser, |
|
561 sessionID, |
|
562 sessionID, |
|
563 iSdpNetType, |
|
564 aHostType, |
|
565 aLocalHost); |
|
566 } |
|
567 |
|
568 // ---------------------------------------------------------------------------- |
|
569 // CSIPOptionsHandler::LocalHostL |
|
570 // ---------------------------------------------------------------------------- |
|
571 // |
|
572 void CSIPOptionsHandler::LocalHostL( |
|
573 CSIPRequest& aRequest, |
|
574 TPtrC8& aLocalHost, |
|
575 RStringF& aHostType) const |
|
576 { |
|
577 CURIContainer* requestURI = aRequest.RequestURI(); |
|
578 if (!requestURI || !requestURI->IsSIPURI()) |
|
579 { |
|
580 User::Leave(KErrSIPInvalidURIType); |
|
581 } |
|
582 const CSIPHostPort& hostPort = requestURI->SIPURI()->HostPort(); |
|
583 aLocalHost.Set(hostPort.Host()); |
|
584 if (hostPort.HostType() == CSIPHostPort::ESIPIpv6) |
|
585 { |
|
586 aHostType = iSdpIPv6Type; |
|
587 } |
|
588 else |
|
589 { |
|
590 aHostType = iSdpIPv4Type; |
|
591 } |
|
592 } |
|
593 |
|
594 // ---------------------------------------------------------------------------- |
|
595 // CSIPOptionsHandler::HasMatchingFmtAttritbute |
|
596 // ---------------------------------------------------------------------------- |
|
597 // |
|
598 TBool CSIPOptionsHandler::HasMatchingFmtAttritbute( |
|
599 CSdpMediaField& aMedia, |
|
600 const CSdpFmtAttributeField& aAttribute) |
|
601 { |
|
602 RPointerArray<CSdpFmtAttributeField>& attributes = |
|
603 aMedia.FormatAttributeFields(); |
|
604 |
|
605 for (TInt i=0; i < attributes.Count(); i++) |
|
606 { |
|
607 if (aAttribute == *attributes[i]) |
|
608 { |
|
609 return ETrue; |
|
610 } |
|
611 } |
|
612 |
|
613 return EFalse; |
|
614 } |
|
615 |
|
616 // ---------------------------------------------------------------------------- |
|
617 // CSIPOptionsHandler::UpdateFormatListL |
|
618 // ---------------------------------------------------------------------------- |
|
619 // |
|
620 void CSIPOptionsHandler::UpdateFormatListL(CSdpMediaField& aMedia) |
|
621 { |
|
622 RPointerArray<CSdpFmtAttributeField>& attributes = |
|
623 aMedia.FormatAttributeFields(); |
|
624 |
|
625 if (aMedia.Protocol() == iRtpAvp && attributes.Count() > 0) |
|
626 { |
|
627 // Calculate length for new format list |
|
628 TInt newFormatListLength = 0; |
|
629 for (TInt i=0; i < attributes.Count(); i++) |
|
630 { |
|
631 newFormatListLength += attributes[i]->Format().Length(); |
|
632 newFormatListLength++; // space |
|
633 } |
|
634 // Create new format list |
|
635 HBufC8* newFormatListBuf = HBufC8::NewLC(newFormatListLength); |
|
636 TPtr8 newFormatListPtr = newFormatListBuf->Des(); |
|
637 for (TInt i=0; i < attributes.Count(); i++) |
|
638 { |
|
639 newFormatListPtr.Append(attributes[i]->Format()); |
|
640 if (i < attributes.Count()-1) |
|
641 { |
|
642 newFormatListPtr.Append(' '); // space |
|
643 } |
|
644 } |
|
645 aMedia.SetFormatListL(newFormatListPtr); |
|
646 CleanupStack::PopAndDestroy(newFormatListBuf); |
|
647 } |
|
648 } |