|
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 : SdpAttributeField.h |
|
15 // Part of : Local SDP Codec |
|
16 // Version : 1.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include <s32strm.h> |
|
22 #include <uri8.h> |
|
23 #include "sdpattributefield.h" |
|
24 #include "sdpattributefieldptrs.h" |
|
25 #include "sdpfmtattributefield.h" |
|
26 #include "sdputil.h" |
|
27 #include "sdpcodec.pan" |
|
28 #include "sdpcodecstringconstants.h" |
|
29 #include "sdpcodecconstants.h" |
|
30 #include "sdpcodecstringpool.h" |
|
31 #include "sdprtpmapvalue.h" |
|
32 #include "sdpcodecerr.h" |
|
33 #include "_sdpdefs.h" |
|
34 |
|
35 // CONSTANTS |
|
36 const TInt KHeaderIndex = 0; |
|
37 const TInt KAttributeIndex = 1; |
|
38 const TInt KMinAttributeNum = 2; |
|
39 const TInt KMaxSubtagLength = 8; |
|
40 const TInt KMaxPrimarySubtagLength = 8; |
|
41 |
|
42 // Valid property attribute strings |
|
43 const TInt KPropertyStringNum = 4; |
|
44 const SdpCodecStringConstants::TStrings |
|
45 KValidPropertyStrings[KPropertyStringNum] = |
|
46 { |
|
47 SdpCodecStringConstants::EAttributeRecvonly, |
|
48 SdpCodecStringConstants::EAttributeSendrecv, |
|
49 SdpCodecStringConstants::EAttributeSendonly, |
|
50 SdpCodecStringConstants::EAttributeInactive |
|
51 }; |
|
52 |
|
53 // Valid value attribute strings |
|
54 const TInt KValueStringNum = 22; |
|
55 const SdpCodecStringConstants::TStrings KValidValueStrings[KValueStringNum] = |
|
56 { |
|
57 SdpCodecStringConstants::EAttributeCat, |
|
58 SdpCodecStringConstants::EAttributeKeywds, |
|
59 SdpCodecStringConstants::EAttributeTool, |
|
60 SdpCodecStringConstants::EAttributePtime, |
|
61 SdpCodecStringConstants::EAttributeMaxptime, |
|
62 SdpCodecStringConstants::EAttributeRtpmap, |
|
63 SdpCodecStringConstants::EAttributeOrient, |
|
64 SdpCodecStringConstants::EAttributeType, |
|
65 SdpCodecStringConstants::EAttributeCharset, |
|
66 SdpCodecStringConstants::EAttributeSdplang, |
|
67 SdpCodecStringConstants::EAttributeLang, |
|
68 SdpCodecStringConstants::EAttributeFramerate, |
|
69 SdpCodecStringConstants::EAttributeQuality, |
|
70 SdpCodecStringConstants::EAttributeFmtp, |
|
71 SdpCodecStringConstants::EAttributeControl, |
|
72 SdpCodecStringConstants::EAttributeEtag, |
|
73 SdpCodecStringConstants::EAttributeMid, |
|
74 SdpCodecStringConstants::EAttributeGroup, |
|
75 SdpCodecStringConstants::EAttributeCurr, |
|
76 SdpCodecStringConstants::EAttributeDes, |
|
77 SdpCodecStringConstants::EAttributeConf, |
|
78 SdpCodecStringConstants::EAttributeRange |
|
79 }; |
|
80 |
|
81 // Valid orient value strings |
|
82 const TInt KValidOrientStringNum = 3; |
|
83 static const TText8* const KOrientStrings[KValidOrientStringNum] = |
|
84 { |
|
85 _S8("portrait\0"), |
|
86 _S8("landscape\0"), |
|
87 _S8("seascape\0") |
|
88 }; |
|
89 |
|
90 const TInt KValidGroupSemanticsNum = 3; |
|
91 static const TText8* const KGroupSemantics[KValidGroupSemanticsNum] = |
|
92 { |
|
93 _S8("LS"), |
|
94 _S8("FID"), |
|
95 _S8("SRF") |
|
96 }; |
|
97 |
|
98 const TInt KValidStatusTypeNum = 3; |
|
99 static const TText8* const KStatusTypes[KValidStatusTypeNum] = |
|
100 { |
|
101 _S8("e2e"), |
|
102 _S8("local"), |
|
103 _S8("remote") |
|
104 }; |
|
105 |
|
106 const TInt KValidDirectionTagsNum = 4; |
|
107 static const TText8* const KDirectionTags[KValidDirectionTagsNum] = |
|
108 { |
|
109 _S8("none"), |
|
110 _S8("send"), |
|
111 _S8("recv"), |
|
112 _S8("sendrecv") |
|
113 }; |
|
114 |
|
115 const TInt KValidStrengthTagsNum = 5; |
|
116 static const TText8* const KStrengthTags[KValidStrengthTagsNum] = |
|
117 { |
|
118 _S8("mandatory"), |
|
119 _S8("optional"), |
|
120 _S8("none"), |
|
121 _S8("failure"), |
|
122 _S8("unknown") |
|
123 }; |
|
124 |
|
125 // ============================ MEMBER FUNCTIONS =============================== |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CSdpAttributeField::CSdpAttributeField |
|
129 // C++ default constructor can NOT contain any code, that |
|
130 // might leave. |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 CSdpAttributeField::CSdpAttributeField() |
|
134 { |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CSdpAttributeField::ConstructL |
|
139 // Symbian 2nd phase constructor can leave. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CSdpAttributeField::ConstructL( const TDesC8& aText ) |
|
143 { |
|
144 // aText should be in format |
|
145 // a=<attribute> or a=<attribute>:<value> or |
|
146 // a=<attribute>:<value> <value specific attributes> |
|
147 |
|
148 __ASSERT_ALWAYS(aText.Length() > 0, User::Leave(KErrSdpCodecAttributeField)); |
|
149 |
|
150 iPool = SdpCodecStringPool::StringPoolL(); |
|
151 CreateAttributeFieldPtrsL(); |
|
152 |
|
153 RArray<TPtrC8> array; |
|
154 |
|
155 TInt length = aText.Length(); |
|
156 if ( aText[aText.Length() - 1] == KLFChar ) |
|
157 { |
|
158 if ( length > 1 && aText[aText.Length() - 2] == KCRChar ) |
|
159 { |
|
160 length--; |
|
161 } |
|
162 length--; |
|
163 } |
|
164 TPtrC8 restValue( aText.Left( length )); |
|
165 |
|
166 __ASSERT_ALWAYS(SdpUtil::IsByteString(restValue) |
|
167 || SdpUtil::IsToken(restValue) |
|
168 || SdpUtil::IsValidChars(KEqualStr, restValue), |
|
169 User::Leave(KErrSdpCodecAttributeField)); |
|
170 |
|
171 array = SdpUtil::GetElementsFromLineL( aText, KErrSdpCodecAttributeField ); |
|
172 CleanupClosePushL( array ); |
|
173 |
|
174 RStringF origHeader = iPool.StringF( SdpCodecStringConstants::EAttribute, |
|
175 SdpCodecStringConstants::Table ); |
|
176 |
|
177 // We need to have at least two tokens (and this should be always the case, |
|
178 // unless TSdpUtil::GetElementsFromLineL() gets modified) |
|
179 __ASSERT_ALWAYS( origHeader.DesC().Compare( array[KHeaderIndex] ) == 0 |
|
180 && array.Count() >= KMinAttributeNum, |
|
181 User::Leave( KErrSdpCodecAttributeField ) ); |
|
182 |
|
183 if ( array[KAttributeIndex].Locate( KColonChar ) == KErrNotFound ) |
|
184 { |
|
185 // For property attributes exactly two attributes are needed |
|
186 __ASSERT_ALWAYS( array.Count() == KMinAttributeNum, |
|
187 User::Leave( KErrSdpCodecAttributeField )); |
|
188 |
|
189 FormatProperyAttributeL( array[KAttributeIndex] ); |
|
190 } |
|
191 else |
|
192 { |
|
193 HBufC8* attribute = NULL; |
|
194 HBufC8* value = NULL; |
|
195 CreateAttributeAndValueStringsLC( array, attribute, value ); |
|
196 FormatValueAttributeL( *attribute, *value ); |
|
197 CleanupStack::PopAndDestroy( 2 ); // attribute, value |
|
198 } |
|
199 |
|
200 CleanupStack::PopAndDestroy(); // array |
|
201 |
|
202 __TEST_INVARIANT; |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CSdpAttributeField::ConstructL |
|
207 // Symbian 2nd phase constructor can leave. |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 void CSdpAttributeField::ConstructL( RStringF aAttribute, |
|
211 const TDesC8& aValue ) |
|
212 { |
|
213 iPool = SdpCodecStringPool::StringPoolL(); |
|
214 CreateAttributeFieldPtrsL(); |
|
215 |
|
216 TBool property( EFalse ); |
|
217 for ( TInt i( 0 ); i < KPropertyStringNum && !property; i++ ) |
|
218 { |
|
219 if ( aAttribute == |
|
220 iPool.StringF( KValidPropertyStrings[i], |
|
221 SdpCodecStringConstants::Table ) ) |
|
222 { |
|
223 property = ETrue; |
|
224 } |
|
225 } |
|
226 |
|
227 if ( property || aValue.Length() == 0) |
|
228 { |
|
229 // For property attributes, no value is valid value |
|
230 __ASSERT_ALWAYS( aValue.Length() == 0, |
|
231 User::Leave( KErrSdpCodecAttributeField )); |
|
232 |
|
233 FormatProperyAttributeL( aAttribute.DesC() ); |
|
234 } |
|
235 else |
|
236 { |
|
237 FormatValueAttributeL( aAttribute.DesC(), aValue ); |
|
238 } |
|
239 |
|
240 __TEST_INVARIANT; |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CSdpAttributeField::DecodeL |
|
245 // Two-phased constructor. |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 EXPORT_C CSdpAttributeField* CSdpAttributeField::DecodeL( const TDesC8& aText ) |
|
249 { |
|
250 CSdpAttributeField* obj = DecodeLC( aText ); |
|
251 CleanupStack::Pop(); |
|
252 return obj; |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CSdpAttributeField::DecodeLC |
|
257 // Two-phased constructor. |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 EXPORT_C CSdpAttributeField* CSdpAttributeField::DecodeLC( |
|
261 const TDesC8& aText ) |
|
262 { |
|
263 CSdpAttributeField* obj = new ( ELeave ) CSdpAttributeField; |
|
264 CleanupStack::PushL( obj ); |
|
265 obj->ConstructL( aText ); |
|
266 return obj; |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CSdpAttributeField::NewL |
|
271 // Two-phased constructor. |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 EXPORT_C CSdpAttributeField* CSdpAttributeField::NewL( RStringF aAttribute, |
|
275 const TDesC8& aValue ) |
|
276 { |
|
277 CSdpAttributeField* obj = NewLC( aAttribute, aValue ); |
|
278 CleanupStack::Pop(); |
|
279 return obj; |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CSdpAttributeField::NewLC |
|
284 // Two-phased constructor. |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 EXPORT_C CSdpAttributeField* CSdpAttributeField::NewLC( RStringF aAttribute, |
|
288 const TDesC8& aValue ) |
|
289 { |
|
290 CSdpAttributeField* obj = new ( ELeave ) CSdpAttributeField; |
|
291 CleanupStack::PushL(obj); |
|
292 obj->ConstructL( aAttribute, aValue ); |
|
293 return obj; |
|
294 } |
|
295 |
|
296 // Destructor |
|
297 EXPORT_C CSdpAttributeField::~CSdpAttributeField() |
|
298 { |
|
299 iAttribute.Close(); |
|
300 CSdpAttributeFieldPtrs* tmp = |
|
301 reinterpret_cast< CSdpAttributeFieldPtrs* >( iValue ); |
|
302 delete tmp; |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CSdpAttributeField::EncodeL |
|
307 // Encodes a string into valid output string format |
|
308 // ----------------------------------------------------------------------------- |
|
309 // |
|
310 EXPORT_C void CSdpAttributeField::EncodeL( RWriteStream& aStream ) const |
|
311 { |
|
312 __TEST_INVARIANT; |
|
313 |
|
314 RStringF header = iPool.StringF( SdpCodecStringConstants::EAttribute, |
|
315 SdpCodecStringConstants::Table ); |
|
316 aStream.WriteL( header.DesC() ); |
|
317 aStream.WriteL( iAttribute.DesC() ); |
|
318 TPtrC8 value( AttributeFieldPtrs().Value() ); |
|
319 if ( value.Length() > 0 ) |
|
320 { |
|
321 aStream.WriteL( KColonStr ); |
|
322 aStream.WriteL( value ); |
|
323 } |
|
324 aStream.WriteL( KCRLFStr ); |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CSdpAttributeField::CloneL |
|
329 // Clones an object and returns the new attribute field |
|
330 // ----------------------------------------------------------------------------- |
|
331 // |
|
332 EXPORT_C CSdpAttributeField * CSdpAttributeField::CloneL() const |
|
333 { |
|
334 __TEST_INVARIANT; |
|
335 |
|
336 CSdpAttributeField* obj = |
|
337 CSdpAttributeField::NewL( iAttribute, AttributeFieldPtrs().Value() ); |
|
338 |
|
339 __ASSERT_DEBUG( *this == *obj, |
|
340 User::Panic(KSdpCodecPanicCat, KSdpCodecPanicInternal) ); |
|
341 return obj; |
|
342 } |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CSdpAttributeField::operator== |
|
346 // Checks if the two attribute fields are equal |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 EXPORT_C TBool CSdpAttributeField::operator== ( |
|
350 const CSdpAttributeField& aObj ) const |
|
351 { |
|
352 __TEST_INVARIANT; |
|
353 |
|
354 return ( iAttribute == aObj.Attribute() && |
|
355 AttributeFieldPtrs().Value().CompareF( aObj.Value() ) == 0 ); |
|
356 } |
|
357 |
|
358 // ----------------------------------------------------------------------------- |
|
359 // CSdpAttributeField::Attribute |
|
360 // Returns attribute part of attribute field |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 EXPORT_C RStringF CSdpAttributeField::Attribute() const |
|
364 { |
|
365 __TEST_INVARIANT; |
|
366 return iAttribute; |
|
367 } |
|
368 |
|
369 // ----------------------------------------------------------------------------- |
|
370 // CSdpAttributeField::Value |
|
371 // Returns value part of attribute field |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 EXPORT_C const TDesC8& CSdpAttributeField::Value() const |
|
375 { |
|
376 __TEST_INVARIANT; |
|
377 |
|
378 return AttributeFieldPtrs().Value(); |
|
379 } |
|
380 |
|
381 // ----------------------------------------------------------------------------- |
|
382 // CSdpAttributeField::SetL |
|
383 // Sets new attribute field values |
|
384 // ----------------------------------------------------------------------------- |
|
385 // |
|
386 EXPORT_C void CSdpAttributeField::SetL( RStringF aAttribute, |
|
387 const TDesC8& aValue ) |
|
388 { |
|
389 __TEST_INVARIANT; |
|
390 |
|
391 ConstructL( aAttribute, aValue ); |
|
392 |
|
393 __TEST_INVARIANT; |
|
394 } |
|
395 |
|
396 // ----------------------------------------------------------------------------- |
|
397 // CSdpAttributeField::AssignTo |
|
398 // Assigns attribute to a format attribute |
|
399 // ----------------------------------------------------------------------------- |
|
400 // |
|
401 EXPORT_C void CSdpAttributeField::AssignTo( |
|
402 const CSdpFmtAttributeField& aFmtAttribute) |
|
403 { |
|
404 AttributeFieldPtrs().SetFmtAttribute(&aFmtAttribute); |
|
405 } |
|
406 |
|
407 // ----------------------------------------------------------------------------- |
|
408 // CSdpAttributeField::BelongsTo |
|
409 // Check if the attribute field belongs to the format attribute |
|
410 // ----------------------------------------------------------------------------- |
|
411 // |
|
412 EXPORT_C TBool CSdpAttributeField::BelongsTo( |
|
413 const CSdpFmtAttributeField& aFmtAttribute) const |
|
414 { |
|
415 return ( AttributeFieldPtrs().FmtAttribute() == &aFmtAttribute ); |
|
416 } |
|
417 |
|
418 // ----------------------------------------------------------------------------- |
|
419 // CSdpAttributeField::ExternalizeL |
|
420 // Externalizes the object to stream |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 void CSdpAttributeField::ExternalizeL( RWriteStream& aStream ) const |
|
424 { |
|
425 // Attribute |
|
426 aStream.WriteUint32L( iAttribute.DesC().Length() ); |
|
427 aStream.WriteL( iAttribute.DesC() ); |
|
428 // Value |
|
429 TPtrC8 value( AttributeFieldPtrs().Value() ); |
|
430 aStream.WriteUint32L( value.Length() ); |
|
431 if ( value.Length() > 0 ) |
|
432 { |
|
433 aStream.WriteL( value, value.Length() ); |
|
434 } |
|
435 } |
|
436 |
|
437 // ----------------------------------------------------------------------------- |
|
438 // CSdpAttributeField::InternalizeL |
|
439 // Internalizes the object from stream |
|
440 // ----------------------------------------------------------------------------- |
|
441 // |
|
442 CSdpAttributeField* CSdpAttributeField::InternalizeL( RReadStream& aStream ) |
|
443 { |
|
444 RStringPool pool = SdpCodecStringPool::StringPoolL(); |
|
445 |
|
446 // Attribute |
|
447 HBufC8* tmpBuf2; |
|
448 TUint32 length = aStream.ReadUint32L(); |
|
449 HBufC8* tmpBuf = HBufC8::NewLC( length ); |
|
450 TPtr8 ptr( tmpBuf->Des() ); |
|
451 aStream.ReadL( ptr, length ); |
|
452 RStringF attribute = pool.OpenFStringL( ptr ); |
|
453 CleanupClosePushL( attribute ); |
|
454 |
|
455 length = aStream.ReadUint32L(); |
|
456 if ( length > 0 ) |
|
457 { |
|
458 tmpBuf2 = HBufC8::NewLC( length ); |
|
459 TPtr8 ptr2( tmpBuf2->Des() ); |
|
460 aStream.ReadL( ptr2, length ); |
|
461 } |
|
462 else |
|
463 { |
|
464 tmpBuf2 = KNullDesC8().AllocLC(); |
|
465 } |
|
466 |
|
467 CSdpAttributeField* obj = CSdpAttributeField::NewL( attribute, *tmpBuf2 ); |
|
468 CleanupStack::PopAndDestroy( 3 ); // attribute, tmpBuf, tmpBuf2 |
|
469 |
|
470 return obj; |
|
471 } |
|
472 |
|
473 // ----------------------------------------------------------------------------- |
|
474 // CSdpAttributeField::FormatPropertyAttributeL |
|
475 // Formats and initializes class to be a property attribute |
|
476 // ----------------------------------------------------------------------------- |
|
477 // |
|
478 void CSdpAttributeField::FormatProperyAttributeL( const TDesC8& aAttribute ) |
|
479 { |
|
480 __ASSERT_ALWAYS( SdpUtil::IsToken( aAttribute ), |
|
481 User::Leave( KErrSdpCodecAttributeField )); |
|
482 |
|
483 TBool found( EFalse ); |
|
484 for ( TInt i( 0 ); i < KPropertyStringNum && !found; i++ ) |
|
485 { |
|
486 RStringF attrString = |
|
487 iPool.StringF( KValidPropertyStrings[i], |
|
488 SdpCodecStringConstants::Table ); |
|
489 |
|
490 if ( attrString.DesC().CompareF( aAttribute ) == 0 ) |
|
491 { |
|
492 AttributeFieldPtrs().SetValueL( KNullDesC8 ); |
|
493 |
|
494 iAttribute.Close(); |
|
495 iAttribute = attrString.Copy(); |
|
496 iPropertyAttribute = ETrue; |
|
497 |
|
498 found = ETrue; |
|
499 } |
|
500 } |
|
501 |
|
502 if ( !found ) |
|
503 { |
|
504 HBufC8* tempValue = KNullDesC8().AllocLC(); |
|
505 SetNotPredefinedAttributeL(aAttribute, *tempValue); |
|
506 CleanupStack::PopAndDestroy(); // tempValue |
|
507 } |
|
508 } |
|
509 |
|
510 // ----------------------------------------------------------------------------- |
|
511 // CSdpAttributeField::FormatValueAttributeL |
|
512 // Formats and initializes class to be a value attribute |
|
513 // ----------------------------------------------------------------------------- |
|
514 // |
|
515 void CSdpAttributeField::FormatValueAttributeL( const TDesC8& aAttribute, |
|
516 const TDesC8& aValue ) |
|
517 { |
|
518 TBool found( EFalse ); |
|
519 |
|
520 __ASSERT_ALWAYS( SdpUtil::IsToken( aAttribute ) |
|
521 && SdpUtil::IsByteString( aValue ), |
|
522 User::Leave( KErrSdpCodecAttributeField ) ); |
|
523 |
|
524 TInt i = 0; |
|
525 for( i = 0; i < KPropertyStringNum && !found; i++) |
|
526 { |
|
527 RStringF attrString = |
|
528 iPool.StringF( KValidPropertyStrings[i], |
|
529 SdpCodecStringConstants::Table ); |
|
530 |
|
531 if ( attrString.DesC().CompareF( aAttribute ) == 0 ) |
|
532 { |
|
533 //found = ETrue; |
|
534 User::Leave(KErrSdpCodecAttributeField); |
|
535 } |
|
536 } |
|
537 |
|
538 for ( i = 0; i < KValueStringNum && !found; i++ ) |
|
539 { |
|
540 RStringF attrString = |
|
541 iPool.StringF( KValidValueStrings[i], |
|
542 SdpCodecStringConstants::Table ); |
|
543 |
|
544 if ( attrString.DesC().CompareF( aAttribute ) == 0 ) |
|
545 { |
|
546 VerifyValueAttributeL( KValidValueStrings[i], aValue ); |
|
547 iAttribute.Close(); |
|
548 iAttribute = attrString.Copy(); |
|
549 found = ETrue; |
|
550 } |
|
551 } |
|
552 |
|
553 if ( !found ) |
|
554 { |
|
555 SetNotPredefinedAttributeL(aAttribute, aValue); |
|
556 } |
|
557 } |
|
558 |
|
559 // ----------------------------------------------------------------------------- |
|
560 // CSdpAttributeField::VerifyValueAttributeL |
|
561 // Verifies that value given to the attribute is valid |
|
562 // ----------------------------------------------------------------------------- |
|
563 // |
|
564 void CSdpAttributeField::VerifyValueAttributeL( |
|
565 SdpCodecStringConstants::TStrings aString, |
|
566 const TDesC8& aValue ) |
|
567 { |
|
568 TUint str( aString ); |
|
569 switch ( str ) |
|
570 { |
|
571 case SdpCodecStringConstants::EAttributeCat: |
|
572 case SdpCodecStringConstants::EAttributeType: |
|
573 case SdpCodecStringConstants::EAttributeCharset: |
|
574 case SdpCodecStringConstants::EAttributeEtag: |
|
575 __ASSERT_ALWAYS( aValue.Length() > 0 |
|
576 && aValue.Locate( KSPChar ) == KErrNotFound, |
|
577 User::Leave( KErrSdpCodecAttributeField ) ); |
|
578 break; |
|
579 |
|
580 case SdpCodecStringConstants::EAttributeKeywds: |
|
581 case SdpCodecStringConstants::EAttributeTool: |
|
582 __ASSERT_ALWAYS( aValue.Length() > 0, |
|
583 User::Leave( KErrSdpCodecAttributeField ) ); |
|
584 break; |
|
585 |
|
586 case SdpCodecStringConstants::EAttributePtime: |
|
587 case SdpCodecStringConstants::EAttributeMaxptime: |
|
588 case SdpCodecStringConstants::EAttributeQuality: |
|
589 __ASSERT_ALWAYS( SdpUtil::IsDigit( aValue ), |
|
590 User::Leave( KErrSdpCodecAttributeField ) ); |
|
591 break; |
|
592 |
|
593 case SdpCodecStringConstants::EAttributeOrient: |
|
594 CheckValidOrientL( aValue ); |
|
595 break; |
|
596 |
|
597 case SdpCodecStringConstants::EAttributeSdplang: |
|
598 case SdpCodecStringConstants::EAttributeLang: |
|
599 CheckValidLangStrL( aValue ); |
|
600 break; |
|
601 |
|
602 case SdpCodecStringConstants::EAttributeFramerate: |
|
603 CheckValidFrameRateL( aValue ); |
|
604 break; |
|
605 |
|
606 case SdpCodecStringConstants::EAttributeControl: |
|
607 CheckValidControlL( aValue ); |
|
608 break; |
|
609 |
|
610 case SdpCodecStringConstants::EAttributeMid: |
|
611 if (SdpUtil::IsToken( aValue ) == EFalse) |
|
612 { |
|
613 User::Leave( KErrSdpCodecAttributeField ); |
|
614 } |
|
615 break; |
|
616 |
|
617 case SdpCodecStringConstants::EAttributeGroup: |
|
618 CheckValidGroupL( aValue ); |
|
619 break; |
|
620 |
|
621 case SdpCodecStringConstants::EAttributeCurr: |
|
622 CheckValidCurrAndConfL( aValue ); |
|
623 break; |
|
624 |
|
625 case SdpCodecStringConstants::EAttributeDes: |
|
626 CheckValidDesL( aValue ); |
|
627 break; |
|
628 |
|
629 case SdpCodecStringConstants::EAttributeConf: |
|
630 CheckValidCurrAndConfL( aValue ); |
|
631 break; |
|
632 |
|
633 case SdpCodecStringConstants::EAttributeRange: |
|
634 CheckValidRangeL( aValue ); |
|
635 break; |
|
636 |
|
637 case SdpCodecStringConstants::EAttributeRtpmap: |
|
638 CheckValidRtpmapL( aValue ); |
|
639 break; |
|
640 |
|
641 case SdpCodecStringConstants::EAttributeFmtp: |
|
642 CheckValidFmtpL( aValue ); |
|
643 break; |
|
644 |
|
645 default: |
|
646 User::Leave( KErrSdpCodecAttributeField ); |
|
647 break; |
|
648 } |
|
649 |
|
650 AttributeFieldPtrs().SetValueL( aValue ); |
|
651 iPropertyAttribute = EFalse; |
|
652 } |
|
653 |
|
654 // ----------------------------------------------------------------------------- |
|
655 // CSdpAttributeField::CreateAttributeAndValueStringsLC |
|
656 // Forms attribute and value strings |
|
657 // ----------------------------------------------------------------------------- |
|
658 // |
|
659 void CSdpAttributeField::CreateAttributeAndValueStringsLC( |
|
660 RArray<TPtrC8>& aArray, |
|
661 HBufC8*& aAttribute, |
|
662 HBufC8*& aValue ) |
|
663 { |
|
664 TInt pos = aArray[KAttributeIndex].Locate( KColonChar ); |
|
665 __ASSERT_ALWAYS( pos > 0, User::Leave( KErrSdpCodecAttributeField ) ); |
|
666 |
|
667 aAttribute = HBufC8::NewLC( pos ); |
|
668 aAttribute->Des().Copy( aArray[KAttributeIndex].Left( pos ) ); |
|
669 |
|
670 // Find out the total length of value string |
|
671 TPtrC8 initialValue( aArray[KAttributeIndex].Right( |
|
672 aArray[KAttributeIndex].Length() - pos - 1 ) ); |
|
673 |
|
674 TInt valueLength( initialValue.Length() ); |
|
675 for ( TInt i( KAttributeIndex + 1 ); i < aArray.Count(); i++ ) |
|
676 { |
|
677 valueLength += KSPStr().Length(); |
|
678 valueLength += aArray[i].Length(); |
|
679 } |
|
680 |
|
681 // Copy the value string to the value buffer |
|
682 aValue = HBufC8::NewLC( valueLength ); |
|
683 aValue->Des().Append( initialValue ); |
|
684 for ( TInt j( KAttributeIndex + 1 ); j < aArray.Count(); j++ ) |
|
685 { |
|
686 aValue->Des().Append( KSPStr ); |
|
687 aValue->Des().Append( aArray[j] ) ; |
|
688 } |
|
689 } |
|
690 |
|
691 // ----------------------------------------------------------------------------- |
|
692 // CSdpAttributeField::CheckValidOrientL |
|
693 // Checks if value is valid orient value |
|
694 // ----------------------------------------------------------------------------- |
|
695 // |
|
696 void CSdpAttributeField::CheckValidOrientL( const TDesC8& aValue ) |
|
697 { |
|
698 TBool found( EFalse ); |
|
699 for ( TInt i( 0 ); i < KValidOrientStringNum && !found; i++ ) |
|
700 { |
|
701 TPtrC8 strPtr( KOrientStrings[i] ); |
|
702 if ( strPtr.CompareF( aValue ) == 0 ) |
|
703 { |
|
704 found = ETrue; |
|
705 } |
|
706 } |
|
707 |
|
708 __ASSERT_ALWAYS(found, User::Leave( KErrSdpCodecAttributeField ) ); |
|
709 } |
|
710 |
|
711 // ----------------------------------------------------------------------------- |
|
712 // CSdpAttributeField::CheckValidLangStrL |
|
713 // Checks if value is valid language tag |
|
714 // ----------------------------------------------------------------------------- |
|
715 // |
|
716 void CSdpAttributeField::CheckValidLangStrL( const TDesC8& aValue ) |
|
717 { |
|
718 // Language-Tag = Primary-subtag *( "-" Subtag ) |
|
719 // Primary-subtag = 1*8ALPHA |
|
720 // Subtag = 1*8(ALPHA / DIGIT) |
|
721 TInt primarySubtagPos = aValue.Locate( KHyphenChar ); |
|
722 |
|
723 if ( primarySubtagPos > KMaxPrimarySubtagLength ) |
|
724 { |
|
725 User::Leave( KErrSdpCodecAttributeField ); |
|
726 } |
|
727 |
|
728 TInt subtagPos( primarySubtagPos ); |
|
729 TPtrC8 ptr( aValue.Right( aValue.Length() - subtagPos - 1 ) ); |
|
730 // Check all subtags |
|
731 while ( subtagPos != ptr.Length() ) |
|
732 { |
|
733 subtagPos = ptr.Locate( KHyphenChar ); |
|
734 |
|
735 if ( subtagPos == KErrNotFound ) |
|
736 { |
|
737 subtagPos = ptr.Length(); |
|
738 } |
|
739 |
|
740 // Check length |
|
741 __ASSERT_ALWAYS( subtagPos > 0 && subtagPos < KMaxSubtagLength, |
|
742 User::Leave( KErrSdpCodecAttributeField ) ); |
|
743 |
|
744 if ( subtagPos != ptr.Length() ) |
|
745 { |
|
746 ptr.Set( aValue.Right( ptr.Length() - subtagPos - 1 ) ); |
|
747 } |
|
748 } |
|
749 } |
|
750 |
|
751 // ----------------------------------------------------------------------------- |
|
752 // CSdpAttributeField::CheckValidFrameRateL |
|
753 // Checks if value is valid framerate value |
|
754 // ----------------------------------------------------------------------------- |
|
755 // |
|
756 void CSdpAttributeField::CheckValidFrameRateL( const TDesC8& aValue ) |
|
757 { |
|
758 TInt dotFound = 0; |
|
759 // There can be one dot and digits |
|
760 for ( TInt i( 0 ); i < aValue.Length(); i++ ) |
|
761 { |
|
762 __ASSERT_ALWAYS((aValue[i] == KDotChar || TChar( aValue[i] ).IsDigit()) |
|
763 && dotFound <= 1, |
|
764 User::Leave( KErrSdpCodecAttributeField )); |
|
765 |
|
766 if ( aValue[i] == KDotChar ) |
|
767 { |
|
768 dotFound++; |
|
769 } |
|
770 } |
|
771 } |
|
772 |
|
773 // ----------------------------------------------------------------------------- |
|
774 // CSdpAttributeField::CheckValidControlL |
|
775 // Checks if value is valid uri for group attribute |
|
776 // ----------------------------------------------------------------------------- |
|
777 // |
|
778 void CSdpAttributeField::CheckValidControlL( const TDesC8& aValue ) |
|
779 { |
|
780 TUriParser8 parser; |
|
781 User::LeaveIfError(parser.Parse(aValue)); |
|
782 } |
|
783 |
|
784 // ----------------------------------------------------------------------------- |
|
785 // CSdpAttributeField::CheckValidGroupL |
|
786 // Checks if value is valid value for group attribute |
|
787 // ----------------------------------------------------------------------------- |
|
788 // |
|
789 void CSdpAttributeField::CheckValidGroupL( const TDesC8& aValue ) |
|
790 { |
|
791 ValidValueInListL(KValidGroupSemanticsNum, KGroupSemantics, aValue); |
|
792 TInt pos = aValue.Locate( KSPChar ); |
|
793 TPtrC8 ptr(aValue); |
|
794 |
|
795 while ( pos != KErrNotFound) |
|
796 { |
|
797 ptr.Set( ptr.Right( ptr.Length() - pos - 1 ) ); |
|
798 pos = ptr.Locate( KSPChar ); |
|
799 } |
|
800 } |
|
801 |
|
802 // ----------------------------------------------------------------------------- |
|
803 // CSdpAttributeField::CheckValidDesL |
|
804 // Checks if value is valid value for des attribute |
|
805 // ----------------------------------------------------------------------------- |
|
806 // |
|
807 void CSdpAttributeField::CheckValidDesL( const TDesC8& aValue ) |
|
808 { |
|
809 TInt pos = aValue.Locate( KSPChar ); |
|
810 __ASSERT_ALWAYS(pos > 0, User::Leave( KErrSdpCodecAttributeField )); |
|
811 TPtrC8 ptr(aValue.Left(pos)); |
|
812 __ASSERT_ALWAYS( SdpUtil::IsToken(ptr), |
|
813 User::Leave( KErrSdpCodecAttributeField ) ); |
|
814 |
|
815 ptr.Set(aValue.Right( aValue.Length() - pos - 1 )); |
|
816 pos = ptr.Locate( KSPChar ); |
|
817 __ASSERT_ALWAYS(pos > 0, User::Leave( KErrSdpCodecAttributeField )); |
|
818 ValidValueInListL(KValidStrengthTagsNum, KStrengthTags, ptr.Left( pos )); |
|
819 |
|
820 ptr.Set(ptr.Right( ptr.Length() - pos - 1 )); |
|
821 pos = ptr.Locate( KSPChar ); |
|
822 __ASSERT_ALWAYS(pos > 0, User::Leave( KErrSdpCodecAttributeField )); |
|
823 ValidValueInListL(KValidStatusTypeNum, KStatusTypes, ptr.Left( pos )); |
|
824 |
|
825 ptr.Set(ptr.Right( ptr.Length() - pos - 1 )); |
|
826 __ASSERT_ALWAYS(ptr.Locate( KSPChar ) == KErrNotFound, |
|
827 User::Leave( KErrSdpCodecAttributeField )); |
|
828 ValidValueInListL(KValidDirectionTagsNum, KDirectionTags, ptr); |
|
829 } |
|
830 |
|
831 // ----------------------------------------------------------------------------- |
|
832 // CSdpAttributeField::CheckValidCurrAndConfL |
|
833 // Checks if value is valid value for curr and conf attribute |
|
834 // ----------------------------------------------------------------------------- |
|
835 // |
|
836 void CSdpAttributeField::CheckValidCurrAndConfL( const TDesC8& aValue ) |
|
837 { |
|
838 TInt pos = aValue.Locate( KSPChar ); |
|
839 __ASSERT_ALWAYS(pos > 0, User::Leave( KErrSdpCodecAttributeField )); |
|
840 TPtrC8 ptr(aValue.Left(pos)); |
|
841 __ASSERT_ALWAYS( SdpUtil::IsToken(ptr), |
|
842 User::Leave( KErrSdpCodecAttributeField ) ); |
|
843 |
|
844 ptr.Set(aValue.Right( aValue.Length() - pos - 1 )); |
|
845 pos = ptr.Locate( KSPChar ); |
|
846 __ASSERT_ALWAYS(pos > 0, User::Leave( KErrSdpCodecAttributeField )); |
|
847 ValidValueInListL(KValidStatusTypeNum, KStatusTypes, ptr.Left( pos )); |
|
848 |
|
849 ptr.Set(ptr.Right( ptr.Length() - pos - 1 )); |
|
850 __ASSERT_ALWAYS(ptr.Locate( KSPChar ) == KErrNotFound, |
|
851 User::Leave( KErrSdpCodecAttributeField )); |
|
852 ValidValueInListL(KValidDirectionTagsNum, KDirectionTags, ptr); |
|
853 } |
|
854 |
|
855 // ----------------------------------------------------------------------------- |
|
856 // CSdpAttributeField::ValidValueInListL |
|
857 // Checks if value is included in predefined values list |
|
858 // ----------------------------------------------------------------------------- |
|
859 // |
|
860 void CSdpAttributeField::ValidValueInListL( TInt aItemsCount, |
|
861 const TText8* const aValuesList[], |
|
862 const TDesC8& aValue ) |
|
863 { |
|
864 TBool found( EFalse ); |
|
865 TInt pos = 0; |
|
866 for ( TInt i( 0 ); i < aItemsCount && !found; i++ ) |
|
867 { |
|
868 TPtrC8 strPtr( aValuesList[i] ); |
|
869 pos = aValue.Find(strPtr); |
|
870 if ( pos != KErrNotFound && pos >= 0 ) |
|
871 { |
|
872 found = ETrue; |
|
873 } |
|
874 } |
|
875 |
|
876 __ASSERT_ALWAYS(found, User::Leave( KErrSdpCodecAttributeField )); |
|
877 } |
|
878 |
|
879 // ----------------------------------------------------------------------------- |
|
880 // CSdpAttributeField::CheckValidCRangefL |
|
881 // Checks if precondition type value is valid value |
|
882 // ----------------------------------------------------------------------------- |
|
883 // |
|
884 void CSdpAttributeField::CheckValidRangeL( const TDesC8& aValue ) |
|
885 { |
|
886 TInt found = aValue.Find(KEqualStr); |
|
887 __ASSERT_ALWAYS(found != KErrNotFound && found > 0, User::Leave( KErrSdpCodecAttributeField )); |
|
888 } |
|
889 |
|
890 // ----------------------------------------------------------------------------- |
|
891 // CSdpAttributeField::CheckValidRtpmapL |
|
892 // Checks if value is valid rtpmap value |
|
893 // ----------------------------------------------------------------------------- |
|
894 // |
|
895 void CSdpAttributeField::CheckValidRtpmapL( const TDesC8& aValue ) |
|
896 { |
|
897 // If this doesn't leave, then the value is OK |
|
898 TSdpRtpmapValue::DecodeL( aValue ); |
|
899 } |
|
900 |
|
901 // ----------------------------------------------------------------------------- |
|
902 // CSdpAttributeField::CheckValidFmtpL |
|
903 // Checks if value is valid format value |
|
904 // ----------------------------------------------------------------------------- |
|
905 // |
|
906 void CSdpAttributeField::CheckValidFmtpL( const TDesC8& aValue ) |
|
907 { |
|
908 __ASSERT_ALWAYS(SdpUtil::IsByteString(aValue) && aValue.Length() > 0, |
|
909 User::Leave( KErrSdpCodecMediaAttributeField )); |
|
910 } |
|
911 |
|
912 // ----------------------------------------------------------------------------- |
|
913 // CSdpAttributeField::SetNotPredefinedAttributeL |
|
914 // Sets attribute and value. Attribute is not one of predefined ones. |
|
915 // ----------------------------------------------------------------------------- |
|
916 // |
|
917 void CSdpAttributeField::SetNotPredefinedAttributeL(const TDesC8& aAttribute, |
|
918 const TDesC8& aValue) |
|
919 { |
|
920 iAttribute.Close(); |
|
921 iAttribute = iPool.OpenFStringL(aAttribute); |
|
922 AttributeFieldPtrs().SetValueL( aValue ); |
|
923 } |
|
924 |
|
925 // ----------------------------------------------------------------------------- |
|
926 // CSdpAttributeField::IsFmtAttribute |
|
927 // Check if the attribute field belongs to any format attribute |
|
928 // ----------------------------------------------------------------------------- |
|
929 // |
|
930 TBool CSdpAttributeField::IsFmtAttribute() |
|
931 { |
|
932 if ( AttributeFieldPtrs().FmtAttribute() ) |
|
933 { |
|
934 return ETrue; |
|
935 } |
|
936 return EFalse; |
|
937 } |
|
938 |
|
939 // ----------------------------------------------------------------------------- |
|
940 // CSdpAttributeField::CreateAttributeFieldPtrsL |
|
941 // ----------------------------------------------------------------------------- |
|
942 // |
|
943 void CSdpAttributeField::CreateAttributeFieldPtrsL() |
|
944 { |
|
945 CSdpAttributeFieldPtrs* newObj = CSdpAttributeFieldPtrs::NewL(); |
|
946 CSdpAttributeFieldPtrs* oldObj = |
|
947 reinterpret_cast< CSdpAttributeFieldPtrs* >( iValue ); |
|
948 delete oldObj; |
|
949 iValue = reinterpret_cast< HBufC8* >( newObj ); |
|
950 } |
|
951 |
|
952 // ----------------------------------------------------------------------------- |
|
953 // CSdpAttributeField::AttributeFieldPtrs |
|
954 // ----------------------------------------------------------------------------- |
|
955 // |
|
956 inline CSdpAttributeFieldPtrs& CSdpAttributeField::AttributeFieldPtrs() |
|
957 { |
|
958 return *( reinterpret_cast< CSdpAttributeFieldPtrs* >( iValue ) ); |
|
959 } |
|
960 |
|
961 // ----------------------------------------------------------------------------- |
|
962 // CSdpAttributeField::AttributeFieldPtrs |
|
963 // ----------------------------------------------------------------------------- |
|
964 // |
|
965 inline const CSdpAttributeFieldPtrs& |
|
966 CSdpAttributeField::AttributeFieldPtrs() const |
|
967 { |
|
968 return *( reinterpret_cast< CSdpAttributeFieldPtrs* >( iValue ) ); |
|
969 } |
|
970 |
|
971 // For DEBUG builds |
|
972 |
|
973 // ----------------------------------------------------------------------------- |
|
974 // CSdpOriginField::__DbgTestInvariant |
|
975 // Test invariant |
|
976 // ----------------------------------------------------------------------------- |
|
977 // |
|
978 void CSdpAttributeField::__DbgTestInvariant() const |
|
979 { |
|
980 TBool invariant = ( |
|
981 SdpUtil::IsToken( iAttribute.DesC() ) |
|
982 && iValue != 0 ); |
|
983 |
|
984 if (!invariant) |
|
985 User::Invariant(); |
|
986 } |