|
1 // Copyright (c) 2010 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 : SdpMediaField.cpp |
|
15 // Part of : Local SDP Codec |
|
16 // Version : 1.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include <s32mem.h> |
|
22 #include <s32strm.h> |
|
23 #include "sdpmediafield.h" |
|
24 #include "sdpconnectionfield.h" |
|
25 #include "sdpbandwidthfield.h" |
|
26 #include "sdpattributefield.h" |
|
27 #include "sdpkeyfield.h" |
|
28 #include "sdpcodecstringconstants.h" |
|
29 #include "sdputil.h" |
|
30 #include "sdpcodec.pan" |
|
31 #include "_sdpdefs.h" |
|
32 #include "sdpcodecstringpool.h" |
|
33 #include "sdpfmtattributefield.h" |
|
34 #include "sdpcodectemplate.h" |
|
35 #include "sdpcodecerr.h" |
|
36 #include "sdpcodecparseutil.h" |
|
37 #include "sdpcodecconstants.h" |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // CSdpMediaField::DecodeL |
|
41 // ---------------------------------------------------------------------------- |
|
42 // |
|
43 EXPORT_C CSdpMediaField* |
|
44 CSdpMediaField::DecodeL(const TDesC8& aText, TBool aRecurse) |
|
45 { |
|
46 CSdpMediaField* obj = DecodeLC(aText,aRecurse); |
|
47 CleanupStack::Pop(); |
|
48 return obj; |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // CSdpMediaField::DecodeLC |
|
53 // ---------------------------------------------------------------------------- |
|
54 // |
|
55 EXPORT_C CSdpMediaField* |
|
56 CSdpMediaField::DecodeLC(const TDesC8& aText, TBool aRecurse) |
|
57 { |
|
58 __ASSERT_ALWAYS (aText.Length() > 0, User::Leave(KErrSdpCodecMediaField)); |
|
59 CSdpMediaField* obj = new(ELeave)CSdpMediaField; |
|
60 CleanupStack::PushL(obj); |
|
61 obj->ConstructL(aRecurse); |
|
62 obj->ParseL(aText); |
|
63 return obj; |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // CSdpMediaField::NewL |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 EXPORT_C CSdpMediaField* CSdpMediaField::NewL(RStringF aMedia, |
|
71 TUint aPort, |
|
72 RStringF aProtocol, |
|
73 const TDesC8& aFormatList) |
|
74 { |
|
75 CSdpMediaField* obj = NewLC(aMedia, aPort, aProtocol, aFormatList); |
|
76 CleanupStack::Pop(); |
|
77 return obj; |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // CSdpMediaField::NewLC |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 EXPORT_C CSdpMediaField* CSdpMediaField::NewLC(RStringF aMedia, |
|
85 TUint aPort, |
|
86 RStringF aProtocol, |
|
87 const TDesC8& aFormatList) |
|
88 { |
|
89 CSdpMediaField* obj = new(ELeave)CSdpMediaField; |
|
90 CleanupStack::PushL(obj); |
|
91 obj->ConstructL(aMedia, aPort, aProtocol, aFormatList); |
|
92 return obj; |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CSdpMediaField::~CSdpMediaField |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 EXPORT_C CSdpMediaField::~CSdpMediaField() |
|
100 { |
|
101 delete iInfo; |
|
102 delete iSdpKeyField; |
|
103 iElementArray.Reset(); |
|
104 iMedia.Close(); |
|
105 iProtocol.Close(); |
|
106 delete iFormatList; |
|
107 delete iToken; |
|
108 if(iBandwidthFields) |
|
109 { |
|
110 iBandwidthFields->ResetAndDestroy(); |
|
111 delete iBandwidthFields; |
|
112 } |
|
113 if(iAttributeFields) |
|
114 { |
|
115 iAttributeFields->ResetAndDestroy(); |
|
116 delete iAttributeFields; |
|
117 } |
|
118 if(iConnectionFields) |
|
119 { |
|
120 iConnectionFields->ResetAndDestroy(); |
|
121 delete iConnectionFields; |
|
122 } |
|
123 if(iFmtAttrFields) |
|
124 { |
|
125 iFmtAttrFields->ResetAndDestroy(); |
|
126 delete iFmtAttrFields; |
|
127 } |
|
128 delete iSdpCodecParseUtil; |
|
129 } |
|
130 |
|
131 // ---------------------------------------------------------------------------- |
|
132 // CSdpMediaField::CloneL |
|
133 // ---------------------------------------------------------------------------- |
|
134 // |
|
135 EXPORT_C CSdpMediaField * CSdpMediaField::CloneL(TBool aRecurse) const |
|
136 { |
|
137 CSdpMediaField* obj = new(ELeave)CSdpMediaField; |
|
138 CleanupStack::PushL(obj); |
|
139 obj->ConstructL(aRecurse); |
|
140 obj->ConstructL(*this); |
|
141 CleanupStack::Pop();//obj |
|
142 return obj; |
|
143 } |
|
144 |
|
145 // ---------------------------------------------------------------------------- |
|
146 // CSdpMediaField::operator == |
|
147 // ---------------------------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C TBool CSdpMediaField::operator == (const CSdpMediaField& aObj) const |
|
150 { |
|
151 TBool result = ETrue; |
|
152 if( !(iMedia==aObj.Media()) || |
|
153 !(iPort == aObj.Port()) || |
|
154 !(iPortCount == aObj.iPortCount) || |
|
155 !(iProtocol == aObj.Protocol()) || |
|
156 !(*iFormatList==(*aObj.iFormatList)) || |
|
157 (!(*iInfo==(*aObj.iInfo)))|| |
|
158 (!iSdpKeyField && aObj.Key())|| |
|
159 (iSdpKeyField && !aObj.Key())|| |
|
160 ((iSdpKeyField && aObj.Key()) && (!(*iSdpKeyField==(*aObj.Key()))))|| |
|
161 (iBandwidthFields->Count() != aObj.iBandwidthFields->Count())|| |
|
162 (iAttributeFields->Count() != aObj.iAttributeFields->Count())|| |
|
163 (iFmtAttrFields->Count() != aObj.iFmtAttrFields->Count())|| |
|
164 (iConnectionFields->Count() != aObj.iConnectionFields->Count())) |
|
165 { |
|
166 result = EFalse; |
|
167 } |
|
168 |
|
169 TInt i = 0; |
|
170 if(result) |
|
171 { |
|
172 for (i=0; i < (aObj.iConnectionFields)->Count(); i++) |
|
173 { |
|
174 if((!(*iConnectionFields)[i] && (*aObj.iConnectionFields)[i]) || |
|
175 ((*iConnectionFields)[i] && !(*aObj.iConnectionFields)[i])) |
|
176 { |
|
177 return EFalse; |
|
178 } |
|
179 |
|
180 if(((*iConnectionFields)[i] && (*aObj.iConnectionFields)[i]) && |
|
181 (!(*(*iConnectionFields)[i]==(*(*aObj.iConnectionFields)[i])))) |
|
182 { |
|
183 return EFalse; |
|
184 } |
|
185 } |
|
186 |
|
187 for (i=0; i < (aObj.iBandwidthFields)->Count(); i++) |
|
188 { |
|
189 if((!(*iBandwidthFields)[i] && (*aObj.iBandwidthFields)[i]) || |
|
190 ((*iBandwidthFields)[i] && !(*aObj.iBandwidthFields)[i])) |
|
191 { |
|
192 return EFalse; |
|
193 } |
|
194 |
|
195 if(((*iBandwidthFields)[i] && (*aObj.iBandwidthFields)[i]) && |
|
196 (!(*(*iBandwidthFields)[i]==(*(*aObj.iBandwidthFields)[i])))) |
|
197 { |
|
198 return EFalse; |
|
199 } |
|
200 } |
|
201 |
|
202 for (i=0; i < (aObj.iAttributeFields)->Count(); i++) |
|
203 { |
|
204 if((!((*iAttributeFields)[i]) && ((*aObj.iAttributeFields)[i]))|| |
|
205 ((*iAttributeFields)[i] && !(*aObj.iAttributeFields)[i])) |
|
206 { |
|
207 return EFalse; |
|
208 } |
|
209 |
|
210 if(((*iAttributeFields)[i] && (*aObj.iAttributeFields)[i]) && |
|
211 (!(*(*iAttributeFields)[i]==(*(*aObj.iAttributeFields)[i])))) |
|
212 { |
|
213 return EFalse; |
|
214 } |
|
215 } |
|
216 |
|
217 for (i=0; i < (aObj.iFmtAttrFields)->Count(); i++) |
|
218 { |
|
219 if((!((*iFmtAttrFields)[i]) && ((*aObj.iFmtAttrFields)[i]))|| |
|
220 ((*iFmtAttrFields)[i] && !(*aObj.iFmtAttrFields)[i])) |
|
221 { |
|
222 return EFalse; |
|
223 } |
|
224 |
|
225 if(((*iFmtAttrFields)[i] && (*aObj.iFmtAttrFields)[i]) && |
|
226 (!(*(*iFmtAttrFields)[i]==(*(*aObj.iFmtAttrFields)[i])))) |
|
227 { |
|
228 return EFalse; |
|
229 } |
|
230 } |
|
231 } |
|
232 return result; |
|
233 } |
|
234 |
|
235 // ---------------------------------------------------------------------------- |
|
236 // CSdpMediaField::Media |
|
237 // ---------------------------------------------------------------------------- |
|
238 // |
|
239 EXPORT_C RStringF CSdpMediaField::Media() const |
|
240 { |
|
241 return iMedia; |
|
242 } |
|
243 |
|
244 // ---------------------------------------------------------------------------- |
|
245 // CSdpMediaField::SetMedia |
|
246 // ---------------------------------------------------------------------------- |
|
247 // |
|
248 EXPORT_C void CSdpMediaField::SetMediaL(RStringF aMedia) |
|
249 { |
|
250 __ASSERT_ALWAYS(SdpUtil::IsTokenChar(aMedia.DesC()), |
|
251 User::Leave(KErrSdpCodecMediaField)); |
|
252 iMedia.Close(); |
|
253 iMedia = aMedia.Copy(); |
|
254 } |
|
255 |
|
256 // ---------------------------------------------------------------------------- |
|
257 // CSdpMediaField::Protocol |
|
258 // ---------------------------------------------------------------------------- |
|
259 // |
|
260 EXPORT_C RStringF CSdpMediaField::Protocol() const |
|
261 { |
|
262 return iProtocol; |
|
263 } |
|
264 |
|
265 // ---------------------------------------------------------------------------- |
|
266 // CSdpMediaField::SetProtocol |
|
267 // ---------------------------------------------------------------------------- |
|
268 // |
|
269 EXPORT_C void CSdpMediaField::SetProtocolL(RStringF aProtocol) |
|
270 { |
|
271 __ASSERT_ALWAYS(SdpUtil::IsTokenCharWithOptionalSlash(aProtocol.DesC()), |
|
272 User::Leave(KErrSdpCodecMediaField)); |
|
273 if (aProtocol == iPool.StringF( SdpCodecStringConstants::EProtocolUdp, |
|
274 SdpCodecStringConstants::Table )) |
|
275 { |
|
276 __ASSERT_ALWAYS((iPort == 0 || (iPort >= 1024 && iPort <= 65535)), |
|
277 User::Leave(KErrSdpCodecMediaField)); |
|
278 } |
|
279 |
|
280 iProtocol.Close(); |
|
281 iProtocol = aProtocol.Copy(); |
|
282 } |
|
283 |
|
284 // ---------------------------------------------------------------------------- |
|
285 // CSdpMediaField::Port |
|
286 // ---------------------------------------------------------------------------- |
|
287 // |
|
288 EXPORT_C TUint CSdpMediaField::Port() const |
|
289 { |
|
290 return iPort; |
|
291 } |
|
292 |
|
293 // ---------------------------------------------------------------------------- |
|
294 // CSdpMediaField::SetPortL |
|
295 // ---------------------------------------------------------------------------- |
|
296 // |
|
297 EXPORT_C void CSdpMediaField::SetPortL(TUint aPort) |
|
298 { |
|
299 if ( iProtocol == iPool.StringF( SdpCodecStringConstants::EProtocolUdp, |
|
300 SdpCodecStringConstants::Table )) |
|
301 { |
|
302 __ASSERT_ALWAYS((aPort == 0 || (aPort >= 1024 && aPort <= 65535)), |
|
303 User::Leave(KErrSdpCodecMediaField)); |
|
304 } |
|
305 iPort = aPort; |
|
306 } |
|
307 |
|
308 // ---------------------------------------------------------------------------- |
|
309 // CSdpMediaField::PortCount |
|
310 // ---------------------------------------------------------------------------- |
|
311 // |
|
312 EXPORT_C TUint CSdpMediaField::PortCount() const |
|
313 { |
|
314 return iPortCount; |
|
315 } |
|
316 |
|
317 // ---------------------------------------------------------------------------- |
|
318 // CSdpMediaField::SetPortCount |
|
319 // ---------------------------------------------------------------------------- |
|
320 // |
|
321 EXPORT_C void CSdpMediaField::SetPortCountL(TUint aCount) |
|
322 { |
|
323 __ASSERT_ALWAYS(aCount > 0, User::Leave(KErrSdpCodecMediaField)); |
|
324 iPortCount = aCount; |
|
325 } |
|
326 |
|
327 // ---------------------------------------------------------------------------- |
|
328 // CSdpMediaField::FormatList |
|
329 // ---------------------------------------------------------------------------- |
|
330 // |
|
331 EXPORT_C const TDesC8& CSdpMediaField::FormatList() const |
|
332 { |
|
333 return *iFormatList; |
|
334 } |
|
335 |
|
336 // ---------------------------------------------------------------------------- |
|
337 // CSdpMediaField::SetFormatListL |
|
338 // ---------------------------------------------------------------------------- |
|
339 // |
|
340 EXPORT_C void CSdpMediaField::SetFormatListL(const TDesC8& aValue) |
|
341 { |
|
342 __ASSERT_ALWAYS(SdpUtil::IsTokenCharWithSpacesL(aValue), |
|
343 User::Leave(KErrSdpCodecMediaField)); |
|
344 HBufC8* tmp = aValue.AllocL(); |
|
345 delete iFormatList; |
|
346 iFormatList = tmp; |
|
347 } |
|
348 |
|
349 // ---------------------------------------------------------------------------- |
|
350 // CSdpMediaField::CSdpMediaField |
|
351 // ---------------------------------------------------------------------------- |
|
352 // |
|
353 CSdpMediaField::CSdpMediaField() |
|
354 { |
|
355 } |
|
356 |
|
357 // ---------------------------------------------------------------------------- |
|
358 // CSdpMediaField::ConstructL |
|
359 // ---------------------------------------------------------------------------- |
|
360 // |
|
361 void CSdpMediaField::ConstructL() |
|
362 { |
|
363 iPool = SdpCodecStringPool::StringPoolL(); |
|
364 iInfo = KNullDesC8().AllocL(); |
|
365 iFormatList = KNullDesC8().AllocL(); |
|
366 iToken = KNullDesC8().AllocL(); |
|
367 iBandwidthFields = new(ELeave)RPointerArray<CSdpBandwidthField>; |
|
368 iConnectionFields = new(ELeave)RPointerArray<CSdpConnectionField>; |
|
369 iAttributeFields = new(ELeave)RPointerArray<CSdpAttributeField>; |
|
370 iFmtAttrFields = new(ELeave)RPointerArray<CSdpFmtAttributeField>; |
|
371 } |
|
372 |
|
373 // ---------------------------------------------------------------------------- |
|
374 // CSdpMediaField::ConstructL |
|
375 // ---------------------------------------------------------------------------- |
|
376 // |
|
377 void CSdpMediaField::ConstructL(TBool aRecurse) |
|
378 { |
|
379 ConstructL(); |
|
380 iRecurse = aRecurse; |
|
381 } |
|
382 |
|
383 // ---------------------------------------------------------------------------- |
|
384 // CSdpMediaField::ConstructL |
|
385 // ---------------------------------------------------------------------------- |
|
386 // |
|
387 void |
|
388 CSdpMediaField::ConstructL(RStringF aMedia, TUint aPort, RStringF aProtocol, |
|
389 const TDesC8& aFormatList) |
|
390 { |
|
391 __ASSERT_ALWAYS(SdpUtil::IsTokenChar(aMedia.DesC()) && |
|
392 (aPort== 0 || (aPort >= 1024 && aPort <= 65535)) && |
|
393 SdpUtil::IsTokenCharWithOptionalSlash(aProtocol.DesC()) && |
|
394 SdpUtil::IsTokenCharWithSpacesL(aFormatList), |
|
395 User::Leave(KErrArgument)); |
|
396 ConstructL(); |
|
397 iMedia = aMedia.Copy(); |
|
398 iProtocol = aProtocol.Copy(); |
|
399 SetPortL(aPort); |
|
400 delete iFormatList; |
|
401 iFormatList = 0; |
|
402 iFormatList = aFormatList.AllocL(); |
|
403 } |
|
404 |
|
405 // ---------------------------------------------------------------------------- |
|
406 // CSdpMediaField::ConstructL |
|
407 // ---------------------------------------------------------------------------- |
|
408 // |
|
409 void CSdpMediaField::ConstructL(const CSdpMediaField& aSdpMediaField) |
|
410 { |
|
411 iMedia = aSdpMediaField.Media().Copy(); |
|
412 iProtocol = aSdpMediaField.Protocol().Copy(); |
|
413 SetPortL(aSdpMediaField.Port()); |
|
414 iPortCount = aSdpMediaField.PortCount(); |
|
415 HBufC8* tmp = aSdpMediaField.FormatList().AllocL(); |
|
416 delete iFormatList; |
|
417 iFormatList = 0; |
|
418 iFormatList = tmp; |
|
419 if(iRecurse) |
|
420 { |
|
421 tmp = aSdpMediaField.Info().AllocL(); |
|
422 delete iInfo; |
|
423 iInfo = tmp; |
|
424 SdpCodecTemplate<CSdpConnectionField>::CloneArrayL(*iConnectionFields, |
|
425 *aSdpMediaField.iConnectionFields); |
|
426 SdpCodecTemplate<CSdpBandwidthField>::CloneArrayL(*iBandwidthFields, |
|
427 *aSdpMediaField.iBandwidthFields); |
|
428 if(aSdpMediaField.Key()) |
|
429 { |
|
430 iSdpKeyField = aSdpMediaField.Key()->CloneL(); |
|
431 } |
|
432 SdpCodecTemplate<CSdpAttributeField>::CloneArrayL(*iAttributeFields, |
|
433 *aSdpMediaField.iAttributeFields); |
|
434 SdpCodecTemplate<CSdpFmtAttributeField>::CloneArrayL(*iFmtAttrFields, |
|
435 *aSdpMediaField.iFmtAttrFields); |
|
436 } |
|
437 } |
|
438 |
|
439 // ---------------------------------------------------------------------------- |
|
440 // CSdpMediaField::Info |
|
441 // ---------------------------------------------------------------------------- |
|
442 // |
|
443 EXPORT_C const TDesC8& CSdpMediaField::Info() const |
|
444 { |
|
445 return *iInfo; |
|
446 } |
|
447 |
|
448 // ---------------------------------------------------------------------------- |
|
449 // CSdpMediaField::SetInfoL |
|
450 // ---------------------------------------------------------------------------- |
|
451 // |
|
452 EXPORT_C void CSdpMediaField::SetInfoL(const TDesC8& aValue) |
|
453 { |
|
454 __ASSERT_ALWAYS (aValue.Compare(KNullDesC8) == 0|| |
|
455 SdpUtil::IsByteString(aValue), |
|
456 User::Leave(KErrSdpCodecMediaInfoField)); |
|
457 HBufC8* tmp = aValue.AllocL(); |
|
458 tmp->Des().Trim(); |
|
459 delete iInfo; |
|
460 iInfo = tmp; |
|
461 } |
|
462 |
|
463 // ---------------------------------------------------------------------------- |
|
464 // CSdpMediaField::Key |
|
465 // ---------------------------------------------------------------------------- |
|
466 // |
|
467 EXPORT_C CSdpKeyField* CSdpMediaField::Key() |
|
468 { |
|
469 return iSdpKeyField; |
|
470 } |
|
471 |
|
472 // ---------------------------------------------------------------------------- |
|
473 // CSdpMediaField::Key |
|
474 // ---------------------------------------------------------------------------- |
|
475 // |
|
476 EXPORT_C const CSdpKeyField* CSdpMediaField::Key() const |
|
477 { |
|
478 return iSdpKeyField; |
|
479 } |
|
480 |
|
481 // ---------------------------------------------------------------------------- |
|
482 // CSdpMediaField::SetKey |
|
483 // ---------------------------------------------------------------------------- |
|
484 // |
|
485 EXPORT_C void CSdpMediaField::SetKey(CSdpKeyField* aObj) |
|
486 { |
|
487 delete iSdpKeyField; |
|
488 iSdpKeyField = aObj; |
|
489 } |
|
490 |
|
491 // ---------------------------------------------------------------------------- |
|
492 // CSdpMediaField::ConnectionFields |
|
493 // ---------------------------------------------------------------------------- |
|
494 // |
|
495 EXPORT_C RPointerArray<CSdpConnectionField>& CSdpMediaField::ConnectionFields() |
|
496 { |
|
497 return *iConnectionFields; |
|
498 } |
|
499 |
|
500 // ---------------------------------------------------------------------------- |
|
501 // CSdpMediaField::BandwidthFields |
|
502 // ---------------------------------------------------------------------------- |
|
503 // |
|
504 EXPORT_C RPointerArray<CSdpBandwidthField>& CSdpMediaField::BandwidthFields() |
|
505 { |
|
506 return *iBandwidthFields; |
|
507 } |
|
508 |
|
509 // ---------------------------------------------------------------------------- |
|
510 // CSdpMediaField::AttributeFields |
|
511 // ---------------------------------------------------------------------------- |
|
512 // |
|
513 EXPORT_C RPointerArray<CSdpAttributeField>& CSdpMediaField::AttributeFields() |
|
514 { |
|
515 return *iAttributeFields; |
|
516 } |
|
517 |
|
518 // ---------------------------------------------------------------------------- |
|
519 // CSdpMediaField::FormatAttributeFields() |
|
520 // ---------------------------------------------------------------------------- |
|
521 // |
|
522 EXPORT_C RPointerArray<CSdpFmtAttributeField>& |
|
523 CSdpMediaField::FormatAttributeFields() |
|
524 { |
|
525 return *iFmtAttrFields; |
|
526 } |
|
527 |
|
528 // ---------------------------------------------------------------------------- |
|
529 // CSdpMediaField::EncodeL |
|
530 // ---------------------------------------------------------------------------- |
|
531 // |
|
532 EXPORT_C void |
|
533 CSdpMediaField::EncodeL(RWriteStream& aStream, TBool aRecurse) const |
|
534 { |
|
535 RStringF headername = iPool.StringF( SdpCodecStringConstants::EMedia, |
|
536 SdpCodecStringConstants::Table ); |
|
537 aStream.WriteL(headername.DesC()); |
|
538 aStream.WriteL(iMedia.DesC()); |
|
539 aStream.WriteL(KSPStr); |
|
540 TBuf8<80> text; |
|
541 text.Format(_L8("%u"), iPort); |
|
542 aStream.WriteL(text); |
|
543 if(iPortCount>0) |
|
544 { |
|
545 aStream.WriteL(_L8("/")); |
|
546 text.Format(_L8("%u"), iPortCount); |
|
547 aStream.WriteL(text); |
|
548 } |
|
549 aStream.WriteL(KSPStr); |
|
550 aStream.WriteL(iProtocol.DesC()); |
|
551 aStream.WriteL(KSPStr); |
|
552 aStream.WriteL(*iFormatList); |
|
553 aStream.WriteL(KCRLFStr); |
|
554 if(aRecurse) |
|
555 { |
|
556 SdpUtil::EncodeBufferL(*iInfo, |
|
557 SdpCodecStringConstants::EInfo, aStream); |
|
558 SdpCodecTemplate<CSdpConnectionField>::EncodeArrayL(*iConnectionFields, |
|
559 aStream); |
|
560 SdpCodecTemplate<CSdpBandwidthField>::EncodeArrayL(*iBandwidthFields, |
|
561 aStream); |
|
562 SdpCodecTemplate<CSdpKeyField>::EncodeL(Key(), aStream); |
|
563 |
|
564 for (TInt i = 0;i < iAttributeFields->Count();i++) |
|
565 { |
|
566 if (!(((*iAttributeFields)[i])->IsFmtAttribute())) |
|
567 { |
|
568 ((*iAttributeFields)[i])->EncodeL(aStream); |
|
569 } |
|
570 } |
|
571 |
|
572 for (TInt i = 0;i < iFmtAttrFields->Count();i++) |
|
573 { |
|
574 ((*iFmtAttrFields)[i])->EncodeL(aStream); |
|
575 |
|
576 for (TInt j=0; j<iAttributeFields->Count(); j++) |
|
577 { |
|
578 if ((((*iAttributeFields)[j])->IsFmtAttribute()) && |
|
579 ((*iAttributeFields)[j])->BelongsTo(*(*iFmtAttrFields)[i])) |
|
580 { |
|
581 ((*iAttributeFields)[j])->EncodeL(aStream); |
|
582 } |
|
583 } |
|
584 } |
|
585 } |
|
586 } |
|
587 |
|
588 // ---------------------------------------------------------------------------- |
|
589 // CSdpMediaField::IsValid |
|
590 // ---------------------------------------------------------------------------- |
|
591 // |
|
592 EXPORT_C TBool CSdpMediaField::IsValid() const |
|
593 { |
|
594 TBool result = EFalse; |
|
595 if(!(iMedia.DesC()==(KNullDesC8)) && |
|
596 !(iProtocol.DesC()==(KNullDesC8))&& |
|
597 !(*iFormatList==(KNullDesC8))) |
|
598 { |
|
599 result = ETrue; |
|
600 } |
|
601 return result; |
|
602 } |
|
603 |
|
604 // ---------------------------------------------------------------------------- |
|
605 // CSdpMediaField::IsContactPresent |
|
606 // ---------------------------------------------------------------------------- |
|
607 // |
|
608 TBool CSdpMediaField::IsContactPresent() const |
|
609 { |
|
610 TBool result = EFalse; |
|
611 if(iConnectionFields->Count() > 0) |
|
612 { |
|
613 result = ETrue; |
|
614 } |
|
615 return result; |
|
616 } |
|
617 |
|
618 // ---------------------------------------------------------------------------- |
|
619 // CSdpMediaField::ExternalizeL |
|
620 // ---------------------------------------------------------------------------- |
|
621 // |
|
622 void CSdpMediaField::ExternalizeL(RWriteStream& aStream) const |
|
623 { |
|
624 aStream.WriteUint32L (iMedia.DesC().Length()); |
|
625 if (iMedia.DesC().Length() > 0) |
|
626 { |
|
627 aStream.WriteL (iMedia.DesC()); |
|
628 } |
|
629 aStream.WriteUint32L (iPort); |
|
630 if(iPortCount) |
|
631 { |
|
632 aStream.WriteUint8L (1); |
|
633 aStream.WriteUint32L (iPortCount); |
|
634 } |
|
635 else |
|
636 { |
|
637 aStream.WriteUint8L (0); |
|
638 } |
|
639 aStream.WriteUint32L (iProtocol.DesC().Length()); |
|
640 if (iProtocol.DesC().Length() > 0) |
|
641 { |
|
642 aStream.WriteL (iProtocol.DesC()); |
|
643 } |
|
644 aStream.WriteUint32L (iFormatList->Length()); |
|
645 if (iFormatList->Length() > 0) |
|
646 { |
|
647 aStream.WriteL (*iFormatList); |
|
648 } |
|
649 aStream.WriteUint32L (iInfo->Length()); |
|
650 if (iInfo->Length() > 0) |
|
651 { |
|
652 aStream.WriteL (*iInfo); |
|
653 } |
|
654 SdpCodecTemplate<CSdpConnectionField>::ExternalizeArrayL(*iConnectionFields, |
|
655 aStream); |
|
656 SdpCodecTemplate<CSdpBandwidthField>::ExternalizeArrayL(*iBandwidthFields, |
|
657 aStream); |
|
658 SdpCodecTemplate<CSdpKeyField>::ExternalizeL(Key(), aStream); |
|
659 SdpCodecTemplate<CSdpAttributeField>::ExternalizeArrayL(*iAttributeFields, |
|
660 aStream); |
|
661 SdpCodecTemplate<CSdpFmtAttributeField>::ExternalizeArrayL(*iFmtAttrFields, |
|
662 aStream); |
|
663 } |
|
664 |
|
665 // ---------------------------------------------------------------------------- |
|
666 // CSdpMediaField::InternalizeL |
|
667 // ---------------------------------------------------------------------------- |
|
668 // |
|
669 CSdpMediaField* CSdpMediaField::InternalizeL(RReadStream& aStream) |
|
670 { |
|
671 CSdpMediaField* obj = new(ELeave)CSdpMediaField(); |
|
672 CleanupStack::PushL(obj); |
|
673 obj->ConstructL(); |
|
674 obj->DoInternalizeL (aStream); |
|
675 CleanupStack::Pop(); |
|
676 return obj; |
|
677 } |
|
678 |
|
679 // ---------------------------------------------------------------------------- |
|
680 // CSdpMediaField::DoInternalizeL |
|
681 // ---------------------------------------------------------------------------- |
|
682 // |
|
683 void CSdpMediaField::DoInternalizeL(RReadStream& aStream) |
|
684 { |
|
685 RStringF media = iPool.OpenFStringL(GetTokenFromStreamL(aStream)); |
|
686 CleanupClosePushL(media); |
|
687 SetMediaL(media); |
|
688 CleanupStack::Pop();//media |
|
689 media.Close(); |
|
690 TUint32 port = aStream.ReadUint32L(); |
|
691 //SetPortL(aStream.ReadUint32L()); |
|
692 TUint flag = aStream.ReadUint8L(); |
|
693 if(flag) |
|
694 { |
|
695 SetPortCountL(aStream.ReadUint32L()); |
|
696 } |
|
697 RStringF protocol =iPool.OpenFStringL(GetTokenFromStreamL(aStream)); |
|
698 CleanupClosePushL(protocol); |
|
699 SetProtocolL(protocol); |
|
700 CleanupStack::Pop();//protocol |
|
701 protocol.Close(); |
|
702 SetPortL(port); |
|
703 SetFormatListL(GetTokenFromStreamL(aStream)); |
|
704 SetInfoL(GetTokenFromStreamL(aStream)); |
|
705 SdpCodecTemplate<CSdpConnectionField>::InternalizeArrayL(*iConnectionFields, |
|
706 aStream); |
|
707 SdpCodecTemplate<CSdpBandwidthField>::InternalizeArrayL(*iBandwidthFields, |
|
708 aStream); |
|
709 if(aStream.ReadUint8L()) |
|
710 { |
|
711 SetKey(CSdpKeyField::InternalizeL(aStream)); |
|
712 } |
|
713 SdpCodecTemplate<CSdpAttributeField>::InternalizeArrayL(*iAttributeFields, |
|
714 aStream); |
|
715 SdpCodecTemplate<CSdpFmtAttributeField>::InternalizeArrayL(*iFmtAttrFields, |
|
716 aStream); |
|
717 } |
|
718 |
|
719 // --------------------------------------------------------------------------- |
|
720 // CSdpMediaField::ParseL |
|
721 // --------------------------------------------------------------------------- |
|
722 // |
|
723 void CSdpMediaField::ParseL (const TDesC8& aText) |
|
724 { |
|
725 iElementArray.Reset(); |
|
726 iSdpCodecParseUtil = |
|
727 CSdpCodecParseUtil::NewL(iPool,aText, KErrSdpCodecMediaField); |
|
728 ParseMediaL(); |
|
729 if(iRecurse) |
|
730 { |
|
731 ParseAttributeFieldsL(); |
|
732 ParseInformationL(); |
|
733 ParseConnectionL(); |
|
734 ParseBandwithL(); |
|
735 ParseEncryptionKeyL(); |
|
736 } |
|
737 } |
|
738 |
|
739 // --------------------------------------------------------------------------- |
|
740 // CSdpMediaField::ParseMediaL |
|
741 // --------------------------------------------------------------------------- |
|
742 // |
|
743 void CSdpMediaField::ParseMediaL() |
|
744 { |
|
745 iElementArray = iSdpCodecParseUtil->FirstLineArrayElementL(iPool, |
|
746 SdpCodecStringConstants::EMedia, |
|
747 KErrSdpCodecMediaField); |
|
748 __ASSERT_ALWAYS (iElementArray.Count() >= 4, |
|
749 User::Leave(KErrSdpCodecMediaField)); |
|
750 |
|
751 RStringF media = iPool.OpenFStringL(iElementArray[1]); |
|
752 CleanupClosePushL(media); |
|
753 SetMediaL(media); |
|
754 CleanupStack::Pop();//media |
|
755 media.Close(); |
|
756 |
|
757 iProtocol = iPool.OpenFStringL(iElementArray[3]); |
|
758 |
|
759 TInt lineEndPosition = iElementArray[2].Locate('/'); |
|
760 TUint port; |
|
761 if(lineEndPosition == KErrNotFound) |
|
762 { |
|
763 User::LeaveIfError( |
|
764 TLex8(iElementArray[2]).Val(port, EDecimal)); |
|
765 SetPortL(port); |
|
766 } |
|
767 else |
|
768 { |
|
769 User::LeaveIfError(TLex8( |
|
770 (iElementArray[2]).Left(lineEndPosition)).Val(port, EDecimal)); |
|
771 SetPortL(port); |
|
772 User::LeaveIfError(TLex8( |
|
773 (iElementArray[2]).Mid(lineEndPosition +1)).Val(port, EDecimal)); |
|
774 SetPortCountL(port); |
|
775 } |
|
776 __ASSERT_ALWAYS(SdpUtil::IsTokenCharWithOptionalSlash(iElementArray[3]), |
|
777 User::Leave(KErrArgument)); |
|
778 |
|
779 //iProtocol = iPool.OpenFStringL(iElementArray[3]); |
|
780 |
|
781 TInt length = 0; |
|
782 TInt i; |
|
783 for(i=4;i<iElementArray.Count();i++) |
|
784 { |
|
785 length += iElementArray[i].Length(); |
|
786 if(i + 1 <iElementArray.Count()) |
|
787 { |
|
788 length += KSPStr().Length(); |
|
789 } |
|
790 } |
|
791 HBufC8* value = HBufC8::NewLC(length); |
|
792 TPtr8 ptr(value->Des()); |
|
793 for(i=4;i<iElementArray.Count();i++) |
|
794 { |
|
795 ptr.Append(iElementArray[i]); |
|
796 if(i + 1 <iElementArray.Count()) |
|
797 { |
|
798 ptr.Append(KSPStr); |
|
799 } |
|
800 } |
|
801 SetFormatListL(*value); |
|
802 CleanupStack::Pop();//value |
|
803 delete value; |
|
804 iElementArray.Reset(); |
|
805 if (iSdpCodecParseUtil->LineArray().Count() > 0) |
|
806 { |
|
807 iSdpCodecParseUtil->LineArray().Remove(0); |
|
808 } |
|
809 } |
|
810 |
|
811 // --------------------------------------------------------------------------- |
|
812 // CSdpMediaField::ParseInformationL |
|
813 // --------------------------------------------------------------------------- |
|
814 // |
|
815 void CSdpMediaField::ParseInformationL() |
|
816 { |
|
817 SetInfoL(iSdpCodecParseUtil->ParseInformationL(KErrSdpCodecMediaInfoField)); |
|
818 } |
|
819 |
|
820 // --------------------------------------------------------------------------- |
|
821 // CSdpMediaField::ParseConnectionL |
|
822 // --------------------------------------------------------------------------- |
|
823 // |
|
824 void CSdpMediaField::ParseConnectionL() |
|
825 { |
|
826 delete iConnectionFields; |
|
827 iConnectionFields = 0; |
|
828 iConnectionFields = iSdpCodecParseUtil->ParseConnectionFieldsL( |
|
829 KErrSdpCodecMediaConnectionField); |
|
830 } |
|
831 |
|
832 // --------------------------------------------------------------------------- |
|
833 // CSdpMediaField::ParseBandwithL |
|
834 // --------------------------------------------------------------------------- |
|
835 // |
|
836 void CSdpMediaField::ParseBandwithL() |
|
837 { |
|
838 delete iBandwidthFields; |
|
839 iBandwidthFields = 0; |
|
840 iBandwidthFields = |
|
841 iSdpCodecParseUtil->ParseBandwidthL(KErrSdpCodecMediaBandwidthField); |
|
842 } |
|
843 |
|
844 // --------------------------------------------------------------------------- |
|
845 // CSdpMediaField::ParseEncryptionKeyL |
|
846 // --------------------------------------------------------------------------- |
|
847 // |
|
848 void CSdpMediaField::ParseEncryptionKeyL() |
|
849 { |
|
850 SetKey(iSdpCodecParseUtil->ParseEncryptionKeyL(KErrSdpCodecMediaKeyField)); |
|
851 } |
|
852 |
|
853 // --------------------------------------------------------------------------- |
|
854 // CSdpMediaField::ParseAttributeFieldsL |
|
855 // --------------------------------------------------------------------------- |
|
856 // |
|
857 void CSdpMediaField::ParseAttributeFieldsL() |
|
858 { |
|
859 CSdpFmtAttributeField* fmtattributefield = 0; |
|
860 |
|
861 RArray<TPtrC8>& lineArray = iSdpCodecParseUtil->LineArray(); |
|
862 for (TInt i=0; i<lineArray.Count(); i++) |
|
863 { |
|
864 iElementArray = CSdpCodecParseUtil::CheckOptionalFieldNameL(iPool, |
|
865 SdpCodecStringConstants::EAttribute, |
|
866 lineArray[i], |
|
867 KErrSdpCodecMediaAttributeField); |
|
868 if (iElementArray.Count()) |
|
869 { |
|
870 CSdpAttributeField* attributefield = |
|
871 CSdpAttributeField::DecodeLC(lineArray[i]); |
|
872 |
|
873 if ( attributefield->Attribute() == |
|
874 iPool.StringF( SdpCodecStringConstants::EAttributeRtpmap, |
|
875 SdpCodecStringConstants::Table ) || |
|
876 attributefield->Attribute() == |
|
877 iPool.StringF( SdpCodecStringConstants::EAttributeFmtp, |
|
878 SdpCodecStringConstants::Table ) ) |
|
879 { |
|
880 CleanupStack::PopAndDestroy(attributefield); |
|
881 fmtattributefield = |
|
882 CSdpFmtAttributeField::DecodeLC(lineArray[i]); |
|
883 iFmtAttrFields->AppendL(fmtattributefield); |
|
884 CleanupStack::Pop(fmtattributefield); |
|
885 } |
|
886 else |
|
887 { |
|
888 iAttributeFields->AppendL(attributefield); |
|
889 CleanupStack::Pop(attributefield); |
|
890 if (fmtattributefield) |
|
891 { |
|
892 attributefield->AssignTo(*fmtattributefield); |
|
893 } |
|
894 } |
|
895 |
|
896 iElementArray.Reset(); |
|
897 lineArray.Remove(i); |
|
898 if (i < lineArray.Count()) |
|
899 { |
|
900 i--; |
|
901 } |
|
902 } |
|
903 } |
|
904 } |
|
905 |
|
906 // --------------------------------------------------------------------------- |
|
907 // CSdpMediaField::GetTokenFromStreamL |
|
908 // --------------------------------------------------------------------------- |
|
909 // |
|
910 TDesC8& CSdpMediaField::GetTokenFromStreamL(RReadStream& aStream) |
|
911 { |
|
912 TUint32 tokenLength = aStream.ReadUint32L(); |
|
913 HBufC8* tmp = 0; |
|
914 if (tokenLength > 0) |
|
915 { |
|
916 tmp = HBufC8::NewLC(tokenLength); |
|
917 TPtr8 tokenptr(tmp->Des()); |
|
918 aStream.ReadL (tokenptr, tokenLength); |
|
919 CleanupStack::Pop();//tmp |
|
920 } |
|
921 else |
|
922 { |
|
923 tmp = KNullDesC8().AllocL(); |
|
924 } |
|
925 delete iToken; |
|
926 iToken = tmp; |
|
927 return *iToken; |
|
928 } |
|
929 |
|
930 // --------------------------------------------------------------------------- |
|
931 // CSdpMediaField::RemoveFormatL |
|
932 // --------------------------------------------------------------------------- |
|
933 // |
|
934 EXPORT_C void CSdpMediaField::RemoveFormatL(const TDesC8& aFormat) |
|
935 { |
|
936 if ( !iFormatList || iFormatList->Des().Length() == 0 ) |
|
937 { |
|
938 User::Leave( KErrSdpCodecMediaField ); |
|
939 } |
|
940 TLex8 lexer( *iFormatList ); |
|
941 TBool tokenRemoved( EFalse ); |
|
942 while ( !tokenRemoved && !lexer.Eos() ) |
|
943 { |
|
944 lexer.SkipSpaceAndMark(); |
|
945 lexer.SkipCharacters(); |
|
946 if ( lexer.TokenLength() > 0 ) |
|
947 { |
|
948 if ( aFormat.CompareF(lexer.MarkedToken()) == 0) |
|
949 { |
|
950 RArray<TInt> removedObjs; |
|
951 CleanupClosePushL( removedObjs ); |
|
952 for ( TInt i( 0 ); i < iFmtAttrFields->Count(); i++ ) |
|
953 { |
|
954 if (aFormat.CompareF((*iFmtAttrFields)[i]->Format()) == 0) |
|
955 { |
|
956 User::LeaveIfError( removedObjs.Append(i) ); |
|
957 } |
|
958 } |
|
959 // Remove all format attributes of type format |
|
960 TInt removedCount( 0 ); |
|
961 while ( removedObjs.Count() > 0 ) |
|
962 { |
|
963 CSdpFmtAttributeField* obj = |
|
964 (*iFmtAttrFields)[removedObjs[0] - removedCount]; |
|
965 delete obj; |
|
966 obj = 0; |
|
967 iFmtAttrFields->Remove( removedObjs[0] - removedCount); |
|
968 removedObjs.Remove(0); |
|
969 removedCount++; |
|
970 } |
|
971 CleanupStack::PopAndDestroy(); // removedObjs |
|
972 |
|
973 // Remove format from format list |
|
974 iFormatList->Des().Delete( lexer.MarkedOffset(), |
|
975 lexer.Offset() - lexer.MarkedOffset()); |
|
976 iFormatList->Des().TrimAll(); |
|
977 tokenRemoved = ETrue; |
|
978 } |
|
979 } |
|
980 } |
|
981 } |
|
982 |
|
983 // --------------------------------------------------------------------------- |
|
984 // CSdpMediaField::KeepFormatL |
|
985 // --------------------------------------------------------------------------- |
|
986 // |
|
987 EXPORT_C void CSdpMediaField::KeepFormatL(const TDesC8& aFormat) |
|
988 { |
|
989 if ( !iFormatList ) |
|
990 { |
|
991 User::Leave( KErrSdpCodecMediaField ); |
|
992 } |
|
993 // Empty set will continue to be empty |
|
994 if ( iFormatList->Des().Length() > 0 ) |
|
995 { |
|
996 HBufC8* formatList = aFormat.AllocLC(); |
|
997 // Mark all format attributes not aFormat so that they will be deleted |
|
998 RArray<TInt> removedObjs; |
|
999 CleanupClosePushL( removedObjs ); |
|
1000 for ( TInt i( 0 ); i < iFmtAttrFields->Count(); i++ ) |
|
1001 { |
|
1002 if (aFormat.CompareF((*iFmtAttrFields)[i]->Format()) != 0) |
|
1003 { |
|
1004 User::LeaveIfError( removedObjs.Append( i ) ); |
|
1005 } |
|
1006 } |
|
1007 // Delete attribute fields |
|
1008 TInt removedCount( 0 ); |
|
1009 while ( removedObjs.Count() > 0 ) |
|
1010 { |
|
1011 CSdpFmtAttributeField* obj = |
|
1012 (*iFmtAttrFields)[removedObjs[0] - removedCount]; |
|
1013 delete obj; |
|
1014 iFmtAttrFields->Remove( removedObjs[0] - removedCount ); |
|
1015 removedObjs.Remove( 0 ); |
|
1016 removedCount++; |
|
1017 } |
|
1018 CleanupStack::PopAndDestroy(); // removedObjs |
|
1019 // Change format list |
|
1020 delete iFormatList; |
|
1021 iFormatList = formatList; |
|
1022 CleanupStack::Pop(); // formatList |
|
1023 } |
|
1024 } |
|
1025 |
|
1026 // --------------------------------------------------------------------------- |
|
1027 // CSdpMediaField::RejectMedia |
|
1028 // --------------------------------------------------------------------------- |
|
1029 // |
|
1030 EXPORT_C void CSdpMediaField::RejectMedia() |
|
1031 { |
|
1032 iPort = 0; |
|
1033 iPortCount = 0; |
|
1034 |
|
1035 TLex8 lexer( *iFormatList ); |
|
1036 lexer.SkipSpaceAndMark(); |
|
1037 lexer.SkipCharacters(); |
|
1038 if ( lexer.TokenLength() > 0 ) |
|
1039 { |
|
1040 TRAPD(err, KeepFormatL( lexer.MarkedToken() )); |
|
1041 err++; // Nothing to do, if error happens. Silence compiler warning. |
|
1042 } |
|
1043 } |
|
1044 |