|
1 // Copyright (c) 2000-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 // attribute value processing |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include <btsdp.h> |
|
20 #include <es_sock.h> |
|
21 #include "attrvalueencoded.h" |
|
22 #include "MAttributeVisitor.h" |
|
23 #include "sdputil.h" |
|
24 #include "DataEncoder.h" |
|
25 |
|
26 const TUint8 KDummyUUIDPointer = 0xff; |
|
27 |
|
28 // ******************* CSdpAttrValue ******************************** |
|
29 |
|
30 CSdpAttrValue::CSdpAttrValue() |
|
31 /** Default constructor. */ |
|
32 { |
|
33 } |
|
34 |
|
35 CSdpAttrValue::~CSdpAttrValue() |
|
36 /** Destructor. */ |
|
37 { |
|
38 } |
|
39 |
|
40 void CSdpAttrValue::AcceptVisitorL(MSdpAttributeValueVisitor& aVisitor) |
|
41 /** Request a call back to pass the attribute value. |
|
42 |
|
43 When called on attributes that are not lists (not DEA or DES), then this calls |
|
44 MSdpAttributeValueVisitor::VisitAttributeValueL(), passing the attribute value |
|
45 object itself (i.e. *this), and the value attribute type. |
|
46 |
|
47 It is more useful when called on a DES or DEA object, as it then provides |
|
48 a simple method of enumerating each attribute in a list. |
|
49 |
|
50 @param aVisitor Abstract interface that can be implemented to receive an enumeration |
|
51 of the values in an attribute list. |
|
52 @see CSdpAttrValueList::AcceptVisitorL() |
|
53 @see MSdpAttributeValueVisitor::VisitAttributeValueL() */ |
|
54 { |
|
55 aVisitor.VisitAttributeValueL(*this, Type()); |
|
56 } |
|
57 |
|
58 |
|
59 // Universal Getters |
|
60 // Defaults are to Panic -- should only be called when overriden |
|
61 |
|
62 TUint CSdpAttrValue::Uint() const |
|
63 /** Gets an unsigned integer attribute value. |
|
64 |
|
65 The base class implementation panics. |
|
66 |
|
67 The size of the unsigned integer should be checked with DataSize() before calling. |
|
68 |
|
69 @return Attribute value */ |
|
70 { |
|
71 DbPanic(ESdpDbBadAttrValueGetter); |
|
72 return 0; |
|
73 } |
|
74 |
|
75 /* |
|
76 UIDs used by the Extension_ method for CSdpAttrValue to identify the function called. |
|
77 |
|
78 @internalComponent |
|
79 */ |
|
80 |
|
81 const TUint KSdpAttrValueUint64FunctionId = 0x1028654A; |
|
82 const TUint KSdpAttrValueUint128FunctionId = 0x1028654B; |
|
83 |
|
84 EXPORT_C void CSdpAttrValue::Uint64(TUint64& aValue) const |
|
85 /** |
|
86 Gets the value as an unsigned 64 bit integer |
|
87 |
|
88 The size of the unsigned integer should be checked with DataSize() before calling. |
|
89 |
|
90 @param aValue A 64 bit unsigned integer |
|
91 */ |
|
92 { |
|
93 TAny* valuePtr = &aValue; |
|
94 const_cast<CSdpAttrValue*>(this)->Extension_(KSdpAttrValueUint64FunctionId, valuePtr, NULL); |
|
95 } |
|
96 |
|
97 EXPORT_C void CSdpAttrValue::Uint128(TUint64& aLo, TUint64& aHi) const |
|
98 /** |
|
99 Gets two TUint64s, one being the high 64 bits and one being the low 64 bits of a 128 bit integer |
|
100 |
|
101 The size of the unsigned integer should be checked with DataSize() before calling. |
|
102 |
|
103 @param aLo The unsigned 64 bit integer contains the lower bits of the 128 bit integer contained in the descriptor |
|
104 @param aHi The unsigned 64 bit integer contains the higher bits of the 128 bit integer contained in the descriptor |
|
105 */ |
|
106 { |
|
107 TAny* loPtr = &aLo; |
|
108 TAny* hiPtr = &aHi; |
|
109 const_cast<CSdpAttrValue*>(this)->Extension_(KSdpAttrValueUint128FunctionId, loPtr, hiPtr); |
|
110 } |
|
111 |
|
112 TInt CSdpAttrValue::Int() const |
|
113 /** Gets a signed integer attribute value. |
|
114 |
|
115 The base class implementation panics. |
|
116 |
|
117 @return Attribute value */ |
|
118 { |
|
119 DbPanic(ESdpDbBadAttrValueGetter); |
|
120 return 0; |
|
121 } |
|
122 |
|
123 TBool CSdpAttrValue::DoesIntFit() const |
|
124 /** Tests if the attribute can be stored in an integer value. |
|
125 |
|
126 The base class implementation returns EFalse. |
|
127 |
|
128 @return True if the attribute can be stored in an integer value */ |
|
129 { |
|
130 return EFalse; |
|
131 } |
|
132 |
|
133 TInt CSdpAttrValue::Bool() const |
|
134 /** Gets a Boolean attribute value. |
|
135 |
|
136 The base class implementation panics. |
|
137 |
|
138 @return Attribute value */ |
|
139 { |
|
140 DbPanic(ESdpDbBadAttrValueGetter); |
|
141 return 0; |
|
142 } |
|
143 |
|
144 const TUUID& CSdpAttrValue::UUID() const |
|
145 /** Gets a UUID attribute value. |
|
146 |
|
147 The base class implementation panics. |
|
148 |
|
149 @return Attribute value */ |
|
150 { |
|
151 DbPanic(ESdpDbBadAttrValueGetter); |
|
152 return *(TUUID*)(KDummyUUIDPointer); |
|
153 } |
|
154 |
|
155 const TPtrC8 CSdpAttrValue::Des() const |
|
156 /** Gets a data buffer attribute value. |
|
157 |
|
158 The base class implementation panics. |
|
159 |
|
160 @return Attribute value */ |
|
161 { |
|
162 DbPanic(ESdpDbBadAttrValueGetter); |
|
163 return TPtrC8(0,0); |
|
164 } |
|
165 |
|
166 /** |
|
167 The extension method provides a polymorphic behaviour to allow interface extension. |
|
168 |
|
169 The base class implementation panics. |
|
170 |
|
171 @internalComponent |
|
172 */ |
|
173 TInt CSdpAttrValue::Extension_(TUint aExtensionId, TAny *&a0, TAny *a1) |
|
174 { |
|
175 TInt ret = KErrNone; |
|
176 switch(aExtensionId) |
|
177 { |
|
178 case KSdpAttrValueUint64FunctionId: |
|
179 case KSdpAttrValueUint128FunctionId: |
|
180 { |
|
181 DbPanic(ESdpDbBadAttrValueGetter); |
|
182 } |
|
183 break; |
|
184 |
|
185 default: |
|
186 { |
|
187 // Chain to base class |
|
188 ret = CBase::Extension_(aExtensionId, a0, a1); |
|
189 } |
|
190 break; |
|
191 } |
|
192 return ret; |
|
193 } |
|
194 |
|
195 // ******************* Concrete CSdpAttrValues ************************ |
|
196 |
|
197 // LIST |
|
198 |
|
199 CSdpAttrValueList::CSdpAttrValueList(MSdpElementBuilder *aParent) |
|
200 : iParent(aParent) |
|
201 { |
|
202 } |
|
203 |
|
204 void CSdpAttrValueList::ConstructL() |
|
205 { |
|
206 iList = new (ELeave) CArrayPtrFlat<CSdpAttrValue> (2); |
|
207 } |
|
208 |
|
209 CSdpAttrValueList::~CSdpAttrValueList() |
|
210 /** Destructor. */ |
|
211 { |
|
212 if ( iList ) |
|
213 { |
|
214 // Destroy all elements on this list |
|
215 iList->ResetAndDestroy(); |
|
216 delete iList; |
|
217 } |
|
218 } |
|
219 |
|
220 void CSdpAttrValueList::AcceptVisitorL(MSdpAttributeValueVisitor& aVisitor) |
|
221 /** Requests a call back to pass the attribute value. |
|
222 |
|
223 This provides a simple method of enumerating each element in the list. |
|
224 |
|
225 @param aVisitor Abstract interface that can be implemented to receive an enumeration |
|
226 of the values in the attribute list. */ |
|
227 { |
|
228 CSdpAttrValue::AcceptVisitorL(aVisitor); |
|
229 aVisitor.StartListL(*this); |
|
230 TInt items = iList->Count(); |
|
231 for (TInt i = 0; i < items; ++i) |
|
232 { |
|
233 (*iList)[i]->AcceptVisitorL(aVisitor); |
|
234 } |
|
235 aVisitor.EndListL(); |
|
236 } |
|
237 |
|
238 TUint CSdpAttrValueList::DataSize() const |
|
239 /** Gets the size of the list. |
|
240 |
|
241 @return Size of the list (in bytes) */ |
|
242 { |
|
243 TUint size = 0; |
|
244 for (TInt i = 0; i < iList->Count(); ++i) |
|
245 { |
|
246 size += TElementEncoder::EncodedSize((*iList)[i]->Type(), (*iList)[i]->DataSize()); |
|
247 } |
|
248 return size; |
|
249 } |
|
250 |
|
251 EXPORT_C void CSdpAttrValueList::AppendValueL(CSdpAttrValue* aValue) |
|
252 /** Add a new value onto the end on this list. |
|
253 |
|
254 Ownership of the passed value is transferred to this list. It will be deleted |
|
255 when the list is destroyed. |
|
256 |
|
257 If a leave occurs, aValue will be cleanup up automatically |
|
258 |
|
259 @param aValue Attribute value to be added onto this list. */ |
|
260 { |
|
261 CleanupStack::PushL(aValue); |
|
262 iList->AppendL(aValue); |
|
263 CleanupStack::Pop(); // aValue |
|
264 } |
|
265 |
|
266 MSdpElementBuilder* CSdpAttrValueList::BuildStringL(const TDesC8& aString) |
|
267 /** Adds a Text String element. |
|
268 @internalTechnology |
|
269 |
|
270 @param aString Attribute to add |
|
271 @return This attribute value with added element */ |
|
272 { |
|
273 CSdpAttrValue *val=CSdpAttrValueString::NewStringL(aString); |
|
274 AppendValueL(val); |
|
275 return this; |
|
276 } |
|
277 |
|
278 MSdpElementBuilder* CSdpAttrValueList::BuildBooleanL(TBool aBool) |
|
279 /** Adds a Boolean element. |
|
280 @internalTechnology |
|
281 |
|
282 @param aBool Attribute to add |
|
283 @return This attribute value with added element */ |
|
284 { |
|
285 CSdpAttrValue *val=CSdpAttrValueBoolean::NewBoolL(aBool); |
|
286 AppendValueL(val); |
|
287 return this; |
|
288 } |
|
289 |
|
290 MSdpElementBuilder* CSdpAttrValueList::BuildDESL() |
|
291 /** Adds a Data element sequence (DES). |
|
292 @internalTechnology |
|
293 |
|
294 This should be followed by a call to StartListL(), and then calls to add elements |
|
295 to the list. |
|
296 |
|
297 @return This attribute value with added element */ |
|
298 { |
|
299 CSdpAttrValueList *val=CSdpAttrValueDES::NewDESL(this); |
|
300 AppendValueL(val); |
|
301 return val; |
|
302 } |
|
303 |
|
304 MSdpElementBuilder* CSdpAttrValueList::BuildDEAL() |
|
305 /** Adds a Data element alternative (DEA). |
|
306 @internalTechnology |
|
307 |
|
308 This should be followed by a call to StartListL(), and then calls to add elements |
|
309 to the list. |
|
310 |
|
311 @return This attribute value with added element */ |
|
312 { |
|
313 CSdpAttrValueList *val=CSdpAttrValueDEA::NewDEAL(this); |
|
314 AppendValueL(val); |
|
315 return val; |
|
316 } |
|
317 |
|
318 MSdpElementBuilder* CSdpAttrValueList::StartListL() |
|
319 /** Indicates that subsequent elements added belong to a DES or DEA. |
|
320 @internalTechnology |
|
321 |
|
322 The end of the list should be indicated by a call to EndList(). |
|
323 |
|
324 @return This attribute value */ |
|
325 { |
|
326 return this; |
|
327 } |
|
328 |
|
329 MSdpElementBuilder* CSdpAttrValueList::EndListL() |
|
330 /** Indicates the end of a list started by StartListL(). |
|
331 @internalTechnology |
|
332 |
|
333 @return Parent of this attribute value */ |
|
334 { |
|
335 return iParent; |
|
336 } |
|
337 |
|
338 MSdpElementBuilder* CSdpAttrValueList::BuildUnknownL(TUint8 /*aType*/, TUint8 /*aSizeDesc*/, const TDesC8& /*aData*/) |
|
339 /** Does nothing. |
|
340 @internalTechnology |
|
341 |
|
342 @return This attribute value */ |
|
343 { |
|
344 //CSdpAttrValue *val=CSdpAttrValueUnknown::NewUnknownL(aType,aSizeDesc,aData); |
|
345 //AppendValueL(val); |
|
346 return this; |
|
347 } |
|
348 |
|
349 MSdpElementBuilder* CSdpAttrValueList::BuildNilL() |
|
350 /** Adds a null type element. |
|
351 @internalTechnology |
|
352 |
|
353 @return This attribute value with added element */ |
|
354 { |
|
355 CSdpAttrValue *val=CSdpAttrValueNil::NewNilL(); |
|
356 AppendValueL(val); |
|
357 return this; |
|
358 } |
|
359 |
|
360 MSdpElementBuilder* CSdpAttrValueList::BuildUintL(const TDesC8& aUint) |
|
361 /** Adds an unsigned integer element. |
|
362 @internalTechnology |
|
363 |
|
364 @param aUint Attribute to add |
|
365 @return This attribute value with added element */ |
|
366 { |
|
367 CSdpAttrValue *val=CSdpAttrValueUint::NewUintL(aUint); |
|
368 AppendValueL(val); |
|
369 return this; |
|
370 } |
|
371 |
|
372 MSdpElementBuilder* CSdpAttrValueList::BuildIntL(const TDesC8& aInt) |
|
373 /** Adds a signed integer element. |
|
374 @internalTechnology |
|
375 |
|
376 @param aInt Attribute to add |
|
377 @return This attribute value with added element */ |
|
378 { |
|
379 CSdpAttrValue *val=CSdpAttrValueInt::NewIntL(aInt); |
|
380 AppendValueL(val); |
|
381 return this; |
|
382 } |
|
383 |
|
384 MSdpElementBuilder* CSdpAttrValueList::BuildUUIDL(const TUUID& aUUID) |
|
385 /** Adds a UUID element. |
|
386 @internalTechnology |
|
387 |
|
388 @param aUUID Attribute to add |
|
389 @return This attribute value with added element */ |
|
390 { |
|
391 CSdpAttrValue *val=CSdpAttrValueUUID::NewUUIDL(aUUID); |
|
392 AppendValueL(val); |
|
393 return this; |
|
394 } |
|
395 |
|
396 MSdpElementBuilder* CSdpAttrValueList::BuildURLL(const TDesC8& aString) |
|
397 /** Adds a URL element. |
|
398 @internalTechnology |
|
399 |
|
400 @param aString URL to add |
|
401 @return This attribute value with added element */ |
|
402 { |
|
403 CSdpAttrValue *val=CSdpAttrValueURL::NewURLL(aString); |
|
404 AppendValueL(val); |
|
405 return this; |
|
406 } |
|
407 |
|
408 MSdpElementBuilder* CSdpAttrValueList::BuildEncodedL(const TDesC8& aString) |
|
409 /** Encode an attribute value. |
|
410 @internalTechnology |
|
411 |
|
412 @param aString The attribute value. |
|
413 @return This attribute value. */ |
|
414 { |
|
415 CSdpAttrValue* val=CSdpAttrValueEncoded::NewEncodedL(aString); |
|
416 AppendValueL(val); |
|
417 return this; |
|
418 } |
|
419 |
|
420 // NIL |
|
421 |
|
422 EXPORT_C CSdpAttrValueNil* CSdpAttrValueNil::NewNilL() |
|
423 /** Allocates and constructs a new CSdpAttrValueNil object. |
|
424 |
|
425 @return New CSdpAttrValueNil */ |
|
426 { |
|
427 CSdpAttrValueNil* val=new (ELeave) CSdpAttrValueNil(); |
|
428 return val; |
|
429 } |
|
430 |
|
431 CSdpAttrValueNil::CSdpAttrValueNil() |
|
432 { |
|
433 } |
|
434 |
|
435 CSdpAttrValueNil::~CSdpAttrValueNil() |
|
436 /** Destructor. */ |
|
437 { |
|
438 } |
|
439 |
|
440 TSdpElementType CSdpAttrValueNil::Type() const |
|
441 /** Gets the type of the attribute (always ETypeNil). |
|
442 |
|
443 @return Type of the attribute */ |
|
444 { |
|
445 return ETypeNil; |
|
446 } |
|
447 |
|
448 TUint CSdpAttrValueNil::DataSize() const |
|
449 /** Gets the size of the attribute (always 0). |
|
450 |
|
451 @return Size of the attribute (in bytes). */ |
|
452 { |
|
453 return 0; |
|
454 } |
|
455 |
|
456 // UINT |
|
457 |
|
458 EXPORT_C CSdpAttrValueUint* CSdpAttrValueUint::NewUintL(const TDesC8 &aUint) |
|
459 /** Allocates and constructs a new CSdpAttrValueUint object. |
|
460 |
|
461 @param aUint Buffer containing an unsigned integer value for the attribute |
|
462 @return New CSdpAttrValueUint object */ |
|
463 { |
|
464 if(aUint.Size()>KSdpMaxUintSize) |
|
465 { |
|
466 //Check less than or equal to 16 bytes = 128 bits |
|
467 User::Leave(KErrArgument); |
|
468 } |
|
469 CSdpAttrValueUint* val=new (ELeave) CSdpAttrValueUint(aUint); |
|
470 return val; |
|
471 } |
|
472 |
|
473 /** |
|
474 Replaces the current value. |
|
475 |
|
476 @param aValue The new value. The provided value must not exceed KSdpMaxUintSize. |
|
477 @panic USER 23 if the supplied value is too long. |
|
478 */ |
|
479 EXPORT_C void CSdpAttrValueUint::SetUintValue(const TDesC8& aValue) |
|
480 { |
|
481 // Copies data into iBuffer |
|
482 iUint = aValue; |
|
483 } |
|
484 |
|
485 CSdpAttrValueUint::CSdpAttrValueUint(const TDesC8 &aUint) |
|
486 : iUint(aUint) |
|
487 { |
|
488 __ASSERT_DEBUG(aUint.Size()<=KSdpMaxUintSize, User::Panic(_L("CSdpAttrValueUint Constructor"), KErrArgument)); |
|
489 } |
|
490 |
|
491 CSdpAttrValueUint::~CSdpAttrValueUint() |
|
492 /** Destructor. */ |
|
493 { |
|
494 } |
|
495 |
|
496 TSdpElementType CSdpAttrValueUint::Type() const |
|
497 /** Gets the attribute type. |
|
498 |
|
499 @return Attribute type. Always ETypeUint. */ |
|
500 { |
|
501 return ETypeUint; |
|
502 } |
|
503 |
|
504 TUint CSdpAttrValueUint::DataSize() const |
|
505 /** Gets the size of the attribute. |
|
506 |
|
507 @return Size of the attribute in bytes */ |
|
508 { |
|
509 return iUint.Length(); |
|
510 } |
|
511 |
|
512 TUint CSdpAttrValueUint::Uint() const |
|
513 /** Gets the value as an unsigned integer type. |
|
514 |
|
515 The size of the unsigned integer should be checked with DataSize() before calling. |
|
516 |
|
517 @return Attribute value */ |
|
518 { |
|
519 return SdpUtil::GetUint(iUint); |
|
520 } |
|
521 |
|
522 TBool CSdpAttrValueUint::DoesIntFit() const |
|
523 /** Tests if the attribute can be stored in an integer value. |
|
524 |
|
525 @return True if the attribute can be stored in an integer value */ |
|
526 { |
|
527 return (iUint.Length()>16)?EFalse:ETrue; |
|
528 } |
|
529 |
|
530 const TPtrC8 CSdpAttrValueUint::Des() const |
|
531 /** Gets the value as a data buffer. |
|
532 |
|
533 @return Attribute value */ |
|
534 { |
|
535 return TPtrC8(iUint); |
|
536 } |
|
537 |
|
538 /** |
|
539 The extension method provides a polymorphic behaviour to allow interface extension. |
|
540 |
|
541 Implements the functions for the Uint64 and Uint128 without breaking binary compatibility |
|
542 |
|
543 @internalComponent |
|
544 */ |
|
545 TInt CSdpAttrValueUint::Extension_(TUint aExtensionId, TAny *&a0, TAny *a1) |
|
546 { |
|
547 switch(aExtensionId) |
|
548 { |
|
549 case KSdpAttrValueUint64FunctionId: |
|
550 { |
|
551 TUint64* value = reinterpret_cast<TUint64*>(a0); |
|
552 SdpUtil::GetUint64(iUint, *value); |
|
553 return KErrNone; |
|
554 } |
|
555 |
|
556 case KSdpAttrValueUint128FunctionId: |
|
557 { |
|
558 TUint64* lo = reinterpret_cast<TUint64*>(a0); |
|
559 TUint64* hi = reinterpret_cast<TUint64*>(a1); |
|
560 SdpUtil::GetUint128(iUint, *lo, *hi); |
|
561 return KErrNone; |
|
562 } |
|
563 |
|
564 default: |
|
565 { |
|
566 // Chain to base class |
|
567 return CSdpAttrValue::Extension_(aExtensionId, a0, a1); |
|
568 } |
|
569 } |
|
570 } |
|
571 |
|
572 // INT |
|
573 |
|
574 EXPORT_C CSdpAttrValueInt* CSdpAttrValueInt::NewIntL(const TDesC8 &aInt) |
|
575 /** Allocates and constructs a new CSdpAttrValueInt object. |
|
576 |
|
577 @param aInt Buffer containing a signed integer value for the attribute |
|
578 @return New CSdpAttrValueInt object */ |
|
579 { |
|
580 if(aInt.Size()>KSdpMaxIntSize) |
|
581 { //Check less than 16 bytes = 128 bits |
|
582 User::Leave(KErrArgument); |
|
583 } |
|
584 CSdpAttrValueInt* val=new (ELeave) CSdpAttrValueInt(aInt); |
|
585 return val; |
|
586 } |
|
587 |
|
588 CSdpAttrValueInt::CSdpAttrValueInt(const TDesC8 &aInt) |
|
589 : iInt(aInt) |
|
590 { |
|
591 __ASSERT_DEBUG(aInt.Size()<=KSdpMaxIntSize, User::Panic(_L("CSdpAttrValueInt Constructor"), KErrArgument)); |
|
592 } |
|
593 |
|
594 CSdpAttrValueInt::~CSdpAttrValueInt() |
|
595 /** Destructor. */ |
|
596 { |
|
597 } |
|
598 |
|
599 TSdpElementType CSdpAttrValueInt::Type() const |
|
600 /** Gets the attribute type. |
|
601 |
|
602 @return Attribute type. Always ETypeInt. */ |
|
603 { |
|
604 return ETypeInt; |
|
605 } |
|
606 |
|
607 TUint CSdpAttrValueInt::DataSize() const |
|
608 /** Gets the size of the attribute. |
|
609 |
|
610 @return Size of the attribute in bytes */ |
|
611 { |
|
612 return iInt.Length(); |
|
613 } |
|
614 |
|
615 TInt CSdpAttrValueInt::Int() const |
|
616 /** Gets the value as a signed integer type. |
|
617 |
|
618 @return Attribute value */ |
|
619 { |
|
620 TUint uint = SdpUtil::GetUint(iInt); |
|
621 switch(iInt.Length()) |
|
622 { |
|
623 case 1: |
|
624 return (TInt8)uint; //cast to remove sign obscuring leading zeros |
|
625 case 2: |
|
626 return (TInt16)uint; //cast to remove sign obscuring leading zeros |
|
627 default: |
|
628 return uint; |
|
629 } |
|
630 } |
|
631 |
|
632 TBool CSdpAttrValueInt::DoesIntFit() const |
|
633 /** Tests if the attribute can be stored in an integer value. |
|
634 |
|
635 @return True if the attribute can be stored in an integer value */ |
|
636 { |
|
637 return (iInt.Length()>4)?EFalse:ETrue; |
|
638 } |
|
639 |
|
640 const TPtrC8 CSdpAttrValueInt::Des() const |
|
641 /** Gets the value as a data buffer. |
|
642 |
|
643 @return Attribute value */ |
|
644 { |
|
645 return TPtrC8(iInt); |
|
646 } |
|
647 |
|
648 // UUID |
|
649 |
|
650 EXPORT_C CSdpAttrValueUUID* CSdpAttrValueUUID::NewUUIDL(const TUUID& aUUID) |
|
651 /** Allocates and constructs a new CSdpAttrValueUUID object. |
|
652 |
|
653 @param aUUID Attribute value |
|
654 @return New CSdpAttrValueUUID object */ |
|
655 { |
|
656 CSdpAttrValueUUID* val=new (ELeave) CSdpAttrValueUUID(aUUID); |
|
657 return val; |
|
658 } |
|
659 |
|
660 CSdpAttrValueUUID::CSdpAttrValueUUID(const TUUID& aUUID) |
|
661 : iUUID(aUUID) |
|
662 { |
|
663 } |
|
664 |
|
665 CSdpAttrValueUUID::~CSdpAttrValueUUID() |
|
666 /** Destructor. */ |
|
667 { |
|
668 } |
|
669 |
|
670 TSdpElementType CSdpAttrValueUUID::Type() const |
|
671 /** Gets the attribute type. |
|
672 |
|
673 @return Attribute type. Always ETypeUUID. */ |
|
674 { |
|
675 return ETypeUUID; |
|
676 } |
|
677 |
|
678 TUint CSdpAttrValueUUID::DataSize() const |
|
679 /** Gets the size of the attribute. |
|
680 |
|
681 @return Size of the attribute in bytes */ |
|
682 {// HACKME change this to vary the UUID size |
|
683 // make sure this is synchronized with Des() |
|
684 return iUUID.ShortestForm().Length(); |
|
685 } |
|
686 |
|
687 const TUUID& CSdpAttrValueUUID::UUID() const |
|
688 /** Gets the attribute value. |
|
689 |
|
690 @return Attribute value */ |
|
691 { |
|
692 return iUUID; |
|
693 } |
|
694 |
|
695 const TPtrC8 CSdpAttrValueUUID::Des() const |
|
696 /** Gets the value as a data buffer. |
|
697 |
|
698 @return Attribute value */ |
|
699 { |
|
700 // return TPtrC8(iUUID.LongForm()); |
|
701 return TPtrC8(iUUID.ShortestForm()); |
|
702 } |
|
703 |
|
704 // STRING |
|
705 |
|
706 EXPORT_C CSdpAttrValueString* CSdpAttrValueString::NewStringL(const TDesC8& aString) |
|
707 /** Allocates and constructs a new CSdpAttrValueString object. |
|
708 |
|
709 @param aString Buffer containing a Text String value for the attribute |
|
710 @return New CSdpAttrValueString object */ |
|
711 { |
|
712 CSdpAttrValueString* st=new (ELeave) CSdpAttrValueString; |
|
713 CleanupStack::PushL(st); |
|
714 st->ConstructL(aString); |
|
715 CleanupStack::Pop(); |
|
716 return st; |
|
717 } |
|
718 |
|
719 void CSdpAttrValueString::ConstructL(const TDesC8& aString) |
|
720 { |
|
721 iBuffer=aString.AllocL(); |
|
722 } |
|
723 |
|
724 CSdpAttrValueString::CSdpAttrValueString() |
|
725 { |
|
726 } |
|
727 |
|
728 CSdpAttrValueString::~CSdpAttrValueString() |
|
729 /** Destructor. */ |
|
730 { |
|
731 delete iBuffer; |
|
732 } |
|
733 |
|
734 TSdpElementType CSdpAttrValueString::Type() const |
|
735 /** Gets the attribute type. |
|
736 |
|
737 @return Attribute type. Always ETypeString. */ |
|
738 { |
|
739 return ETypeString; |
|
740 } |
|
741 |
|
742 TUint CSdpAttrValueString::DataSize() const |
|
743 /** Gets the size of the attribute. |
|
744 |
|
745 @return Size of the attribute in bytes */ |
|
746 { |
|
747 return (*iBuffer).Length(); |
|
748 } |
|
749 |
|
750 const TPtrC8 CSdpAttrValueString::Des() const |
|
751 /** Gets the value as a data buffer. |
|
752 |
|
753 @return Attribute value */ |
|
754 { |
|
755 return TPtrC8(iBuffer->Des()); |
|
756 } |
|
757 |
|
758 // BOOL |
|
759 |
|
760 EXPORT_C CSdpAttrValueBoolean* CSdpAttrValueBoolean::NewBoolL(TBool aBool) |
|
761 /** Allocates and constructs a new CSdpAttrValueBoolean object. |
|
762 |
|
763 @param aBool Value for the attribute |
|
764 @return New CSdpAttrValueBoolean object */ |
|
765 { |
|
766 CSdpAttrValueBoolean* val=new (ELeave) CSdpAttrValueBoolean(aBool); |
|
767 return val; |
|
768 } |
|
769 |
|
770 CSdpAttrValueBoolean::CSdpAttrValueBoolean(TBool aBool) |
|
771 : iBool(aBool) |
|
772 { |
|
773 } |
|
774 |
|
775 CSdpAttrValueBoolean::~CSdpAttrValueBoolean() |
|
776 /** Destructor. */ |
|
777 { |
|
778 } |
|
779 |
|
780 TSdpElementType CSdpAttrValueBoolean::Type() const |
|
781 /** Gets the attribute type. |
|
782 |
|
783 @return Attribute type. Always ETypeBoolean. */ |
|
784 { |
|
785 return ETypeBoolean; |
|
786 } |
|
787 |
|
788 TUint CSdpAttrValueBoolean::DataSize() const |
|
789 /** Gets the size of the attribute. |
|
790 |
|
791 @return Size of the attribute in bytes. Always 1. */ |
|
792 { |
|
793 return 1; |
|
794 } |
|
795 |
|
796 TBool CSdpAttrValueBoolean::Bool() const |
|
797 /** Gets the attribute value. |
|
798 |
|
799 @return Attribute value */ |
|
800 { |
|
801 return iBool; |
|
802 } |
|
803 |
|
804 |
|
805 // DES |
|
806 |
|
807 EXPORT_C CSdpAttrValueDES* CSdpAttrValueDES::NewDESL(MSdpElementBuilder* aBuilder) |
|
808 /** Allocates and constructs a new CSdpAttrValueDES object. |
|
809 |
|
810 @param aBuilder Parent for list. Set to NULL if the list is not nested in |
|
811 another list. |
|
812 @return A new CSdpAttrValueDES object */ |
|
813 { |
|
814 CSdpAttrValueDES* self=new (ELeave) CSdpAttrValueDES(aBuilder); |
|
815 CleanupStack::PushL(self); |
|
816 self->CSdpAttrValueList::ConstructL(); |
|
817 CleanupStack::Pop(); |
|
818 return self; |
|
819 } |
|
820 |
|
821 CSdpAttrValueDES::CSdpAttrValueDES(MSdpElementBuilder *aBuilder) |
|
822 : CSdpAttrValueList(aBuilder) |
|
823 { |
|
824 } |
|
825 |
|
826 TSdpElementType CSdpAttrValueDES::Type() const |
|
827 /** Gets the attribute type. |
|
828 |
|
829 @return Attribute type. Always ETypeDES. */ |
|
830 { |
|
831 return ETypeDES; |
|
832 } |
|
833 |
|
834 // DEA |
|
835 |
|
836 EXPORT_C CSdpAttrValueDEA* CSdpAttrValueDEA::NewDEAL(MSdpElementBuilder* aBuilder) |
|
837 /** Allocates and constructs a new CSdpAttrValueDEA object. |
|
838 |
|
839 @param aBuilder Parent for list. Set to NULL if the list is not nested in |
|
840 another list. |
|
841 @return A new CSdpAttrValueDEA object */ |
|
842 { |
|
843 CSdpAttrValueDEA* self=new (ELeave) CSdpAttrValueDEA(aBuilder); |
|
844 CleanupStack::PushL(self); |
|
845 self->CSdpAttrValueList::ConstructL(); |
|
846 CleanupStack::Pop(); |
|
847 return self; |
|
848 } |
|
849 |
|
850 CSdpAttrValueDEA::CSdpAttrValueDEA(MSdpElementBuilder *aBuilder) |
|
851 : CSdpAttrValueList(aBuilder) |
|
852 { |
|
853 } |
|
854 |
|
855 /** Gets the attribute type. |
|
856 |
|
857 @return Attribute type. Always ETypeDEA. */ |
|
858 TSdpElementType CSdpAttrValueDEA::Type() const |
|
859 { |
|
860 return ETypeDEA; |
|
861 } |
|
862 |
|
863 |
|
864 // URL |
|
865 |
|
866 /** Allocates and constructs a new CSdpAttrValueURL object. |
|
867 |
|
868 @param aString Buffer containing the attribute value |
|
869 @return New CSdpAttrValueURL object */ |
|
870 EXPORT_C CSdpAttrValueURL* CSdpAttrValueURL::NewURLL(const TDesC8& aURL) |
|
871 { |
|
872 CSdpAttrValueURL* st=new (ELeave) CSdpAttrValueURL; |
|
873 CleanupStack::PushL(st); |
|
874 st->ConstructL(aURL); |
|
875 CleanupStack::Pop(); |
|
876 return st; |
|
877 } |
|
878 |
|
879 void CSdpAttrValueURL::ConstructL(const TDesC8& aURL) |
|
880 { |
|
881 iBuffer=aURL.AllocL(); |
|
882 } |
|
883 |
|
884 CSdpAttrValueURL::CSdpAttrValueURL() |
|
885 { |
|
886 } |
|
887 |
|
888 CSdpAttrValueURL::~CSdpAttrValueURL() |
|
889 /** Destructor. */ |
|
890 { |
|
891 delete iBuffer; |
|
892 } |
|
893 |
|
894 TSdpElementType CSdpAttrValueURL::Type() const |
|
895 /** Gets the attribute type. |
|
896 |
|
897 @return Attribute type. Always ETypeURL. */ |
|
898 { |
|
899 return ETypeURL; |
|
900 } |
|
901 |
|
902 TUint CSdpAttrValueURL::DataSize() const |
|
903 /** Gets the size of the attribute. |
|
904 |
|
905 @return Size of the attribute in bytes. */ |
|
906 { |
|
907 return (*iBuffer).Length(); |
|
908 } |
|
909 |
|
910 const TPtrC8 CSdpAttrValueURL::Des() const |
|
911 /** Gets the value as a data buffer. |
|
912 |
|
913 @return Attribute value */ |
|
914 { |
|
915 return TPtrC8(iBuffer->Des()); |
|
916 } |
|
917 |
|
918 // Encoded |
|
919 |
|
920 EXPORT_C CSdpAttrValueEncoded* CSdpAttrValueEncoded::NewEncodedL(const TDesC8& aString) |
|
921 { |
|
922 CSdpAttrValueEncoded* st=new(ELeave) CSdpAttrValueEncoded(); |
|
923 CleanupStack::PushL(st); |
|
924 st->ConstructL(aString); |
|
925 CleanupStack::Pop(); |
|
926 return st; |
|
927 } |
|
928 |
|
929 void CSdpAttrValueEncoded::ConstructL(const TDesC8& aString) |
|
930 { |
|
931 iBuffer=aString.AllocL(); |
|
932 } |
|
933 |
|
934 CSdpAttrValueEncoded::CSdpAttrValueEncoded() |
|
935 { |
|
936 } |
|
937 |
|
938 CSdpAttrValueEncoded::~CSdpAttrValueEncoded() |
|
939 { |
|
940 delete iBuffer; |
|
941 } |
|
942 |
|
943 TSdpElementType CSdpAttrValueEncoded::Type() const |
|
944 { |
|
945 return ETypeEncoded; |
|
946 } |
|
947 |
|
948 TUint CSdpAttrValueEncoded::DataSize() const |
|
949 { |
|
950 return iBuffer->Length(); |
|
951 } |
|
952 |
|
953 const TPtrC8 CSdpAttrValueEncoded::Des() const |
|
954 { |
|
955 return TPtrC8(iBuffer->Des()); |
|
956 } |
|
957 |
|
958 /** |
|
959 Replaces the current value. |
|
960 |
|
961 @param aValue The new value. This must be an attribute value which has been |
|
962 appropriately encoded, for instance using the CSdpAttrEncoderVisitor |
|
963 class. The data in aValue will be copied. The provided value must |
|
964 not exceed the length of the current data. This may be retrieved |
|
965 via the CSdpAttrValueEncoded::Des() function and TPtrC8::Length() |
|
966 function. |
|
967 @panic USER 23 if the supplied value is too long. |
|
968 */ |
|
969 EXPORT_C void CSdpAttrValueEncoded::SetEncodedValue(const TDesC8& aValue) |
|
970 { |
|
971 // Copies data into iBuffer |
|
972 *iBuffer = aValue; |
|
973 } |
|
974 |