realtimenetprots/sipfw/SDP/src/SdpDocument.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name          : SdpDocument.cpp
       
    15 // Part of       : SDP Codec
       
    16 // Version       : 1.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include <s32strm.h>
       
    22 #include <e32std.h>
       
    23 #include "SdpDocument.h"
       
    24 #include "SdpTimeField.h"
       
    25 #include "SdpBandwidthField.h"
       
    26 #include "SdpAttributeField.h"
       
    27 #include "SdpMediaField.h"
       
    28 #include "SdpConnectionField.h"
       
    29 #include "SdpKeyField.h"
       
    30 #include "SdpOriginField.h"
       
    31 #include "SdpRepeatField.h"
       
    32 #include "sdpcodecstringconstants.h"
       
    33 #include "SdpCodecErr.h"
       
    34 #include "SdpCodecConstants.h"
       
    35 #include "uri8.h"
       
    36 #include "uriutilscommon.h"
       
    37 #include "badesca.h"
       
    38 #include "_sdpdefs.h"
       
    39 #include "SdpCodecStringPool.h"
       
    40 #include "SdpUtil.h"
       
    41 #include "SdpCodecTemplate.h"
       
    42 #include "SdpCodecParseUtil.h"
       
    43 
       
    44 _LIT8(KCRLF, "\r\n");
       
    45 // ----------------------------------------------------------------------------
       
    46 // CSdpDocument::DecodeL
       
    47 // ----------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C CSdpDocument* 
       
    50 CSdpDocument::DecodeL(const TDesC8& aText)
       
    51 	{
       
    52 	CSdpDocument* sdpDocument = CSdpDocument::DecodeLC(aText);
       
    53 	CleanupStack::Pop();
       
    54 	return sdpDocument;
       
    55 	}
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // CSdpDocument::DecodeLC
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C CSdpDocument* 
       
    62 CSdpDocument::DecodeLC(const TDesC8& aText)
       
    63 	{
       
    64 	__ASSERT_ALWAYS (aText.Length() > 0, User::Leave(KErrArgument));
       
    65 	CSdpDocument* sdpDocument = new(ELeave)CSdpDocument;
       
    66 	CleanupStack::PushL(sdpDocument);
       
    67 	sdpDocument->ConstructL();
       
    68 	sdpDocument->ParseL(aText);
       
    69 	return sdpDocument;
       
    70 	}
       
    71 
       
    72 // ----------------------------------------------------------------------------
       
    73 // CSdpDocument::NewL
       
    74 // ----------------------------------------------------------------------------
       
    75 //
       
    76 EXPORT_C CSdpDocument* CSdpDocument::NewL()
       
    77 	{
       
    78 	CSdpDocument* self = CSdpDocument::NewLC();
       
    79 	CleanupStack::Pop();
       
    80 	return self;
       
    81 	}
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CSdpDocument::NewLC
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 EXPORT_C CSdpDocument* CSdpDocument::NewLC()
       
    88 	{
       
    89 	CSdpDocument* self = new(ELeave)CSdpDocument;
       
    90 	CleanupStack::PushL(self);
       
    91 	self->ConstructL();
       
    92 	return self;
       
    93 	}
       
    94 
       
    95 // ----------------------------------------------------------------------------
       
    96 // CSdpDocument::~CSdpDocument
       
    97 // ----------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C CSdpDocument::~CSdpDocument()
       
   100 	{
       
   101 	delete iInfo;
       
   102 	delete iSessionName;
       
   103 	delete iZoneAdjustments;
       
   104 	delete iSdpKeyField;
       
   105 	delete iSdpOriginField;
       
   106 	delete iSdpConnectionField;
       
   107 	if(iTimeFields)
       
   108 		{
       
   109 		iTimeFields->ResetAndDestroy();
       
   110 		delete iTimeFields;
       
   111 		}
       
   112 	if(iBandwidthFields)
       
   113 		{
       
   114 		iBandwidthFields->ResetAndDestroy();
       
   115 		delete iBandwidthFields;
       
   116 		}
       
   117 	if(iAttributeFields)
       
   118 		{
       
   119 		iAttributeFields->ResetAndDestroy();
       
   120 		delete iAttributeFields;
       
   121 		}
       
   122 	if(iMediaFields)
       
   123 		{
       
   124 		iMediaFields->ResetAndDestroy();
       
   125 		delete iMediaFields;
       
   126 		}
       
   127 	delete iUri;
       
   128 	if(iEmailFields)
       
   129 		{
       
   130 		iEmailFields->Reset();
       
   131 		delete iEmailFields;
       
   132 		}
       
   133 
       
   134 	if(iPhoneFields)
       
   135 		{
       
   136 		iPhoneFields->Reset();
       
   137 		delete iPhoneFields;
       
   138 		}
       
   139 	delete iToken;
       
   140 	delete iSdpCodecParseUtil;
       
   141 	}
       
   142 
       
   143 // ----------------------------------------------------------------------------
       
   144 // CSdpDocument::ExternalizeL
       
   145 // ----------------------------------------------------------------------------
       
   146 //
       
   147 EXPORT_C void CSdpDocument::ExternalizeL(RWriteStream& aStream) const
       
   148 	{
       
   149 	aStream.WriteUint32L (iSdpVersion);	
       
   150 	SdpCodecTemplate<CSdpOriginField>::ExternalizeL(OriginField(), aStream);
       
   151 	aStream.WriteUint32L (iSessionName->Length());
       
   152 	if (iSessionName->Length() > 0)
       
   153 		{
       
   154 		aStream.WriteL (*iSessionName);
       
   155 		}
       
   156 	aStream.WriteUint32L (iInfo->Length());
       
   157 	if (iInfo->Length() > 0)
       
   158 		{
       
   159 		aStream.WriteL (*iInfo);
       
   160 		}
       
   161 	if(Uri())
       
   162 		{
       
   163 		aStream.WriteUint8L (1);
       
   164 		aStream.WriteUint32L ((iUri->Uri()).UriDes().Length());
       
   165 		aStream.WriteL((iUri->Uri()).UriDes());
       
   166 		}
       
   167 	else
       
   168 		{
       
   169 		aStream.WriteUint8L (0);
       
   170 		}
       
   171 	ExternalizeDesCArrayL(*iEmailFields, aStream);
       
   172 	ExternalizeDesCArrayL(*iPhoneFields, aStream);
       
   173 
       
   174 	SdpCodecTemplate<CSdpConnectionField>::ExternalizeL(iSdpConnectionField,
       
   175 														aStream);
       
   176 	SdpCodecTemplate<CSdpBandwidthField>::ExternalizeArrayL(*iBandwidthFields,
       
   177 															aStream);
       
   178 	SdpCodecTemplate<CSdpTimeField>::ExternalizeArrayL(*iTimeFields, aStream);
       
   179 	aStream.WriteUint32L (iZoneAdjustments->Length());
       
   180 	if (iZoneAdjustments->Length() > 0)
       
   181 		{
       
   182 		aStream.WriteL (*iZoneAdjustments);
       
   183 		}
       
   184 	SdpCodecTemplate<CSdpKeyField>::ExternalizeL(Key(), aStream);
       
   185 	SdpCodecTemplate<CSdpAttributeField>::ExternalizeArrayL(*iAttributeFields,
       
   186 															aStream);
       
   187 	SdpCodecTemplate<CSdpMediaField>::ExternalizeArrayL(*iMediaFields, 
       
   188 															aStream);
       
   189 	}
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CSdpDocument::InternalizeL
       
   193 // ----------------------------------------------------------------------------
       
   194 //
       
   195 EXPORT_C CSdpDocument* 
       
   196 CSdpDocument::InternalizeL(RReadStream& aStream)
       
   197 	{
       
   198 	CSdpDocument* self = new(ELeave)CSdpDocument;
       
   199 	CleanupStack::PushL(self);
       
   200 	self->ConstructL();
       
   201 	self->DoInternalizeL (aStream);
       
   202 	CleanupStack::Pop();
       
   203 	return self;
       
   204 	}
       
   205 
       
   206 // ----------------------------------------------------------------------------
       
   207 // CSdpDocument::DoInternalizeL
       
   208 // ----------------------------------------------------------------------------
       
   209 //
       
   210 void CSdpDocument::DoInternalizeL(RReadStream& aStream)
       
   211 	{
       
   212 	if(iTimeFields)
       
   213 		{
       
   214 		iTimeFields->ResetAndDestroy();
       
   215 		}
       
   216 	iSdpVersion = aStream.ReadUint32L();
       
   217 	if(aStream.ReadUint8L())
       
   218 		{
       
   219 		SetOriginField(CSdpOriginField::InternalizeL(aStream));
       
   220 		}
       
   221 	SetSessionNameL(GetTokenFromStreamL(aStream));
       
   222 	SetInfoL(GetTokenFromStreamL(aStream));
       
   223 	if(aStream.ReadUint8L())
       
   224 		{
       
   225 		TUriParser8 parser;
       
   226 		User::LeaveIfError(parser.Parse(GetTokenFromStreamL(aStream)));
       
   227 		SetUri(CUri8::NewL(parser));
       
   228 		}
       
   229 	TInt i = 0;
       
   230 	TInt count = aStream.ReadUint32L();
       
   231 	for (i = 0;i < count;i++)
       
   232 		{
       
   233 		TPtrC8 temp(GetTokenFromStreamL(aStream));
       
   234 		if(temp.Compare(KNullDesC8) != 0)
       
   235 			{
       
   236 			iEmailFields->AppendL(temp);
       
   237 			}
       
   238 		}
       
   239 	count = aStream.ReadUint32L();
       
   240 	for (i = 0;i < count;i++)
       
   241 		{
       
   242 		TPtrC8 temp(GetTokenFromStreamL(aStream));
       
   243 		if(temp.Compare(KNullDesC8) != 0)
       
   244 			{
       
   245 			iPhoneFields->AppendL(temp);
       
   246 			}
       
   247 		}
       
   248 	if(aStream.ReadUint8L())
       
   249 		{
       
   250 		SetConnectionField(CSdpConnectionField::InternalizeL(aStream));
       
   251 		}
       
   252 	SdpCodecTemplate<CSdpBandwidthField>::InternalizeArrayL(
       
   253 												*iBandwidthFields, aStream);
       
   254 	SdpCodecTemplate<CSdpTimeField>::InternalizeArrayL(*iTimeFields,
       
   255 														aStream);
       
   256 	SetZoneAdjustmentsL(GetTokenFromStreamL(aStream));
       
   257 	if(aStream.ReadUint8L())
       
   258 		{
       
   259 		SetKey(CSdpKeyField::InternalizeL(aStream));
       
   260 		}
       
   261 	SdpCodecTemplate<CSdpAttributeField>::InternalizeArrayL(
       
   262 												*iAttributeFields, aStream);
       
   263 	SdpCodecTemplate<CSdpMediaField>::InternalizeArrayL(*iMediaFields,
       
   264 															aStream);
       
   265 	}
       
   266 
       
   267 // ----------------------------------------------------------------------------
       
   268 // CSdpDocument::EncodeL
       
   269 // ----------------------------------------------------------------------------
       
   270 //
       
   271 EXPORT_C void CSdpDocument::EncodeL(RWriteStream& aStream) const
       
   272 	{
       
   273 	RStringF headername = iPool.StringF( SdpCodecStringConstants::EVersion, 
       
   274                                               SdpCodecStringConstants::Table );
       
   275     aStream.WriteL(headername.DesC());
       
   276 	TBuf8<80> text;
       
   277 	text.Format(_L8("%u"), iSdpVersion);
       
   278 	aStream.WriteL(text);
       
   279 	aStream.WriteL(KCRLF);	
       
   280 	SdpCodecTemplate<CSdpOriginField>::EncodeL(OriginField(), aStream);
       
   281 	SdpUtil::EncodeBufferL(*iSessionName, SdpCodecStringConstants::ESession,
       
   282 																	aStream);
       
   283 	SdpUtil::EncodeBufferL(*iInfo, SdpCodecStringConstants::EInfo, aStream);
       
   284 	if(Uri())
       
   285 		{
       
   286 		SdpUtil::EncodeBufferL(((iUri->Uri()).UriDes()), 
       
   287 					SdpCodecStringConstants::EUri, aStream);
       
   288 		}
       
   289 	EncodeDesCArrayL(*iEmailFields, SdpCodecStringConstants::EEmail, aStream);
       
   290 	EncodeDesCArrayL(*iPhoneFields, SdpCodecStringConstants::EPhone, aStream);
       
   291 	SdpCodecTemplate<CSdpConnectionField>::EncodeL(iSdpConnectionField,
       
   292 														aStream);
       
   293 	SdpCodecTemplate<CSdpBandwidthField>::EncodeArrayL(*iBandwidthFields,
       
   294 														aStream);
       
   295 	SdpCodecTemplate<CSdpTimeField>::EncodeArrayL(*iTimeFields, aStream);
       
   296 	SdpUtil::EncodeBufferL(*iZoneAdjustments,
       
   297 							SdpCodecStringConstants::EZone, aStream);
       
   298 	SdpCodecTemplate<CSdpKeyField>::EncodeL(Key(), aStream);
       
   299 	SdpCodecTemplate<CSdpAttributeField>::EncodeArrayL(*iAttributeFields, 
       
   300 														aStream);
       
   301 	SdpCodecTemplate<CSdpMediaField>::EncodeArrayL(*iMediaFields, aStream);
       
   302 	}
       
   303 
       
   304 // ----------------------------------------------------------------------------
       
   305 // CSdpDocument::CloneL
       
   306 // ----------------------------------------------------------------------------
       
   307 //
       
   308 EXPORT_C CSdpDocument* CSdpDocument::CloneL() const
       
   309 	{
       
   310 	CSdpDocument* sdpdocument = new(ELeave)CSdpDocument;
       
   311 	CleanupStack::PushL(sdpdocument);
       
   312 	sdpdocument->ConstructL(*this);
       
   313 	CleanupStack::Pop();//sdpdocument
       
   314 	return sdpdocument;
       
   315 	}
       
   316 
       
   317 // ----------------------------------------------------------------------------
       
   318 // CSdpDocument::IsValid
       
   319 // ----------------------------------------------------------------------------
       
   320 //
       
   321 EXPORT_C TBool CSdpDocument::IsValid() const
       
   322 	{
       
   323 	if (iTimeFields->Count() == 0 || !OriginField() ||
       
   324         !SessionName().Length()||
       
   325 		(!iMediaFields->Count() && !ConnectionField()))
       
   326 		{
       
   327 		return EFalse;
       
   328 		}
       
   329     TInt j;
       
   330 	for (j=0; j < iMediaFields->Count(); j++)
       
   331 		{
       
   332 		if(!(*iMediaFields)[j]->IsValid() || 
       
   333 			(!ConnectionField() && (!(*iMediaFields)[j]->IsContactPresent())))
       
   334 			{
       
   335 			return EFalse;
       
   336 			}
       
   337 		}
       
   338     
       
   339     for (j=0; j < iTimeFields->Count(); j++)
       
   340 		{
       
   341         if ( !(*iTimeFields)[j]->IsValid())
       
   342             {
       
   343 		    return EFalse;
       
   344             }
       
   345 		}
       
   346 	return ETrue;
       
   347 	}
       
   348 
       
   349 // ----------------------------------------------------------------------------
       
   350 // CSdpDocument::SdpVersion
       
   351 // ----------------------------------------------------------------------------
       
   352 //
       
   353 EXPORT_C TUint CSdpDocument::SdpVersion() const
       
   354 	{
       
   355 	return iSdpVersion;
       
   356 	}
       
   357 
       
   358 // ----------------------------------------------------------------------------
       
   359 // CSdpDocument::OriginField
       
   360 // ----------------------------------------------------------------------------
       
   361 //
       
   362 EXPORT_C CSdpOriginField* CSdpDocument::OriginField()
       
   363 	{
       
   364 	return iSdpOriginField;
       
   365 	}
       
   366 
       
   367 // ----------------------------------------------------------------------------
       
   368 // CSdpDocument::OriginField
       
   369 // ----------------------------------------------------------------------------
       
   370 //
       
   371 EXPORT_C const CSdpOriginField* CSdpDocument::OriginField() const
       
   372 	{
       
   373 	return iSdpOriginField;
       
   374 	}
       
   375 
       
   376 // ----------------------------------------------------------------------------
       
   377 // CSdpDocument::SetOriginField
       
   378 // ----------------------------------------------------------------------------
       
   379 //
       
   380 EXPORT_C void CSdpDocument::SetOriginField(CSdpOriginField* aObj)
       
   381 	{
       
   382 	delete iSdpOriginField;
       
   383 	iSdpOriginField = aObj;
       
   384 	}
       
   385 
       
   386 // ----------------------------------------------------------------------------
       
   387 // CSdpDocument::SessionName
       
   388 // ----------------------------------------------------------------------------
       
   389 //
       
   390 EXPORT_C const TDesC8& CSdpDocument::SessionName() const
       
   391 	{
       
   392 	return *iSessionName;
       
   393 	}
       
   394 
       
   395 // ----------------------------------------------------------------------------
       
   396 // CSdpDocument::SetSessionNameL
       
   397 // ----------------------------------------------------------------------------
       
   398 //
       
   399 EXPORT_C void CSdpDocument::SetSessionNameL(const TDesC8& aValue)
       
   400 	{
       
   401 	__ASSERT_ALWAYS (aValue.Compare(KNullDesC8) == 0||
       
   402 					aValue.Compare(_L8(" ")) == 0||
       
   403 					SdpUtil::IsByteString(aValue),
       
   404 	                 User::Leave(KErrSdpCodecSessionField));
       
   405 	HBufC8* tmp = aValue.AllocL();
       
   406 	delete iSessionName;
       
   407 	iSessionName = tmp;
       
   408 	}
       
   409 
       
   410 // ----------------------------------------------------------------------------
       
   411 // CSdpDocument::Info
       
   412 // ----------------------------------------------------------------------------
       
   413 //
       
   414 EXPORT_C const TDesC8& CSdpDocument::Info() const
       
   415 	{
       
   416 	return *iInfo;
       
   417 	}
       
   418 
       
   419 // ----------------------------------------------------------------------------
       
   420 // CSdpDocument::SetInfoL
       
   421 // ----------------------------------------------------------------------------
       
   422 //
       
   423 EXPORT_C void CSdpDocument::SetInfoL(const TDesC8& aValue)
       
   424 	{
       
   425 	__ASSERT_ALWAYS (aValue.Compare(KNullDesC8) == 0||
       
   426 					SdpUtil::IsByteString(aValue),
       
   427 	                 User::Leave(KErrSdpCodecInfoField));
       
   428 	HBufC8* tmp = aValue.AllocL();
       
   429 	tmp->Des().Trim();
       
   430 	delete iInfo;
       
   431 	iInfo = tmp;
       
   432 	}
       
   433 
       
   434 // ----------------------------------------------------------------------------
       
   435 // CSdpDocument::Uri
       
   436 // ----------------------------------------------------------------------------
       
   437 //
       
   438 EXPORT_C CUri8* CSdpDocument::Uri() 
       
   439 	{
       
   440 	return iUri;
       
   441 	}
       
   442 
       
   443 // ----------------------------------------------------------------------------
       
   444 // CSdpDocument::Uri
       
   445 // ----------------------------------------------------------------------------
       
   446 //
       
   447 EXPORT_C const CUri8* CSdpDocument::Uri() const
       
   448 	{
       
   449 	return iUri;
       
   450 	}
       
   451 
       
   452 // ----------------------------------------------------------------------------
       
   453 // CSdpDocument::SetUriL
       
   454 // ----------------------------------------------------------------------------
       
   455 //
       
   456 EXPORT_C void CSdpDocument::SetUri(CUri8* aValue)
       
   457 	{
       
   458 	delete iUri;
       
   459 	iUri = aValue;
       
   460 	}
       
   461 
       
   462 // ----------------------------------------------------------------------------
       
   463 // CSdpDocument::EmailFields
       
   464 // ----------------------------------------------------------------------------
       
   465 //
       
   466 EXPORT_C CDesC8Array& CSdpDocument::EmailFields()
       
   467 	{
       
   468 	return *iEmailFields;
       
   469 	}
       
   470 
       
   471 // ----------------------------------------------------------------------------
       
   472 // CSdpDocument::PhoneFields
       
   473 // ----------------------------------------------------------------------------
       
   474 //
       
   475 EXPORT_C CDesC8Array& CSdpDocument::PhoneFields()
       
   476 	{
       
   477 	return *iPhoneFields;
       
   478 	}
       
   479 
       
   480 // ----------------------------------------------------------------------------
       
   481 // CSdpDocument::ConnectionField
       
   482 // ----------------------------------------------------------------------------
       
   483 //
       
   484 EXPORT_C CSdpConnectionField* CSdpDocument::ConnectionField()
       
   485 	{
       
   486 	return iSdpConnectionField;
       
   487 	}
       
   488 
       
   489 // ----------------------------------------------------------------------------
       
   490 // CSdpDocument::ConnectionField
       
   491 // ----------------------------------------------------------------------------
       
   492 //
       
   493 EXPORT_C const CSdpConnectionField* CSdpDocument::ConnectionField() const
       
   494 	{
       
   495 	return iSdpConnectionField;
       
   496 	}
       
   497 
       
   498 // ----------------------------------------------------------------------------
       
   499 // CSdpDocument::SetConnectionField
       
   500 // ----------------------------------------------------------------------------
       
   501 //
       
   502 EXPORT_C void CSdpDocument::SetConnectionField(CSdpConnectionField* aObj)
       
   503 	{
       
   504 	delete iSdpConnectionField;
       
   505 	iSdpConnectionField = aObj;
       
   506 	}
       
   507 
       
   508 // ----------------------------------------------------------------------------
       
   509 // CSdpDocument::BandwidthFields
       
   510 // ----------------------------------------------------------------------------
       
   511 //
       
   512 EXPORT_C RPointerArray<CSdpBandwidthField>& CSdpDocument::BandwidthFields()
       
   513 	{
       
   514 	return *iBandwidthFields;
       
   515 	}
       
   516 
       
   517 // ----------------------------------------------------------------------------
       
   518 // CSdpDocument::TimeFields
       
   519 // ----------------------------------------------------------------------------
       
   520 //
       
   521 EXPORT_C RPointerArray<CSdpTimeField>& CSdpDocument::TimeFields()
       
   522 	{
       
   523 	return *iTimeFields;
       
   524 	}
       
   525 
       
   526 // ----------------------------------------------------------------------------
       
   527 // CSdpDocument::ZoneAdjustments
       
   528 // ----------------------------------------------------------------------------
       
   529 //
       
   530 EXPORT_C const TDesC8& CSdpDocument::ZoneAdjustments() const
       
   531 	{
       
   532 	return *iZoneAdjustments;
       
   533 	}
       
   534 
       
   535 // ----------------------------------------------------------------------------
       
   536 // CSdpDocument::SetZoneAdjustmentsL
       
   537 // ----------------------------------------------------------------------------
       
   538 //
       
   539 EXPORT_C void CSdpDocument::SetZoneAdjustmentsL(const TDesC8& aValue)
       
   540 	{
       
   541 	HBufC8* tmp = aValue.AllocL();
       
   542 	tmp->Des().Trim();
       
   543 	delete iZoneAdjustments;
       
   544 	iZoneAdjustments = tmp;
       
   545 	}
       
   546 
       
   547 // ----------------------------------------------------------------------------
       
   548 // CSdpDocument::Key
       
   549 // ----------------------------------------------------------------------------
       
   550 //
       
   551 EXPORT_C CSdpKeyField* CSdpDocument::Key()
       
   552 	{
       
   553 	return iSdpKeyField;
       
   554 	}
       
   555 
       
   556 // ----------------------------------------------------------------------------
       
   557 // CSdpDocument::Key
       
   558 // ----------------------------------------------------------------------------
       
   559 //
       
   560 EXPORT_C const CSdpKeyField* CSdpDocument::Key() const
       
   561 	{
       
   562 	return iSdpKeyField;
       
   563 	}
       
   564 
       
   565 // ----------------------------------------------------------------------------
       
   566 // CSdpDocument::SetKey
       
   567 // ----------------------------------------------------------------------------
       
   568 //
       
   569 EXPORT_C void CSdpDocument::SetKey(CSdpKeyField* aObj)
       
   570 	{
       
   571 	delete iSdpKeyField;
       
   572 	iSdpKeyField = aObj;
       
   573 	}
       
   574 
       
   575 // ----------------------------------------------------------------------------
       
   576 // CSdpDocument::AttributeFields
       
   577 // ----------------------------------------------------------------------------
       
   578 //
       
   579 EXPORT_C RPointerArray<CSdpAttributeField>& CSdpDocument::AttributeFields()
       
   580 	{
       
   581 	return *iAttributeFields;
       
   582 	}
       
   583 
       
   584 // ----------------------------------------------------------------------------
       
   585 // CSdpDocument::MediaFields
       
   586 // ----------------------------------------------------------------------------
       
   587 //
       
   588 EXPORT_C RPointerArray<CSdpMediaField>& CSdpDocument::MediaFields()
       
   589 	{
       
   590 	return *iMediaFields;
       
   591 	}
       
   592 	
       
   593 // ----------------------------------------------------------------------------
       
   594 // CSdpDocument::CSdpDocument
       
   595 // ----------------------------------------------------------------------------
       
   596 //
       
   597 CSdpDocument::CSdpDocument()
       
   598 	{
       
   599 	}
       
   600 	
       
   601 // ----------------------------------------------------------------------------
       
   602 // CSdpDocument::ConstructL
       
   603 // ----------------------------------------------------------------------------
       
   604 //
       
   605 void CSdpDocument::ConstructL()
       
   606 	{
       
   607 	iPool = SdpCodecStringPool::StringPoolL();
       
   608 	iInfo = KNullDesC8().AllocL();
       
   609 	iSessionName = KNullDesC8().AllocL();
       
   610 	iZoneAdjustments = KNullDesC8().AllocL();
       
   611 	iSdpVersion = 0;
       
   612 	iEmailFields = new(ELeave)CDesC8ArraySeg(1);
       
   613 	iPhoneFields = new(ELeave)CDesC8ArraySeg(1);
       
   614 	iBandwidthFields = new(ELeave)RPointerArray<CSdpBandwidthField>;
       
   615 	iTimeFields = new(ELeave)RPointerArray<CSdpTimeField>;
       
   616 	iAttributeFields = new(ELeave)RPointerArray<CSdpAttributeField>;
       
   617 	iMediaFields = new(ELeave)RPointerArray<CSdpMediaField>;
       
   618 	CSdpTimeField* timefield = CSdpTimeField::NewLC(_L8("0"),_L8("0"));
       
   619 	User::LeaveIfError(iTimeFields->Append(timefield));
       
   620 	CleanupStack::Pop();
       
   621 	iToken = KNullDesC8().AllocL();
       
   622 	}
       
   623 
       
   624 // ----------------------------------------------------------------------------
       
   625 // CSdpDocument::ConstructL
       
   626 // ----------------------------------------------------------------------------
       
   627 //
       
   628 void CSdpDocument::ConstructL(const CSdpDocument& aSdpDocument)
       
   629 	{
       
   630 	ConstructL();
       
   631 	iSdpVersion = aSdpDocument.SdpVersion();
       
   632 	if ( aSdpDocument.OriginField() )
       
   633 		{
       
   634 		iSdpOriginField = aSdpDocument.OriginField()->CloneL();
       
   635 		}
       
   636 	delete iSessionName;
       
   637 	iSessionName = 0;
       
   638 	iSessionName = aSdpDocument.SessionName().AllocL();
       
   639 	HBufC8* tmp = aSdpDocument.Info().AllocL();
       
   640 	delete iInfo;
       
   641 	iInfo = tmp;
       
   642 	if ( aSdpDocument.Uri() )
       
   643 		{
       
   644 		iUri = CUri8::NewL(aSdpDocument.Uri()->Uri());
       
   645 		}
       
   646 	TInt i = 0;
       
   647 	for ( i=0; i < (aSdpDocument.iEmailFields)->MdcaCount(); i++ )
       
   648 		{
       
   649 		iEmailFields->AppendL(aSdpDocument.iEmailFields->MdcaPoint(i));
       
   650 		}
       
   651 
       
   652 	for (i=0; i < (aSdpDocument.iPhoneFields)->MdcaCount(); i++)
       
   653 		{
       
   654 		iPhoneFields->AppendL(aSdpDocument.iPhoneFields->MdcaPoint(i));
       
   655 		}
       
   656 
       
   657 	if ( aSdpDocument.ConnectionField() )
       
   658 		{
       
   659 		iSdpConnectionField = aSdpDocument.ConnectionField()->CloneL();
       
   660 		}
       
   661 	SdpCodecTemplate<CSdpBandwidthField>::CloneArrayL(*iBandwidthFields, 
       
   662 											*aSdpDocument.iBandwidthFields);
       
   663 	if ( iTimeFields )
       
   664 		{
       
   665 		iTimeFields->ResetAndDestroy();
       
   666 		}
       
   667 	SdpCodecTemplate<CSdpTimeField>::CloneArrayL(*iTimeFields, 
       
   668 												*aSdpDocument.iTimeFields);
       
   669 	delete iZoneAdjustments;
       
   670 	iZoneAdjustments = 0;
       
   671 	iZoneAdjustments = aSdpDocument.ZoneAdjustments().AllocL();
       
   672 	if(aSdpDocument.Key())
       
   673 		{
       
   674 		iSdpKeyField = aSdpDocument.Key()->CloneL();
       
   675 		}
       
   676 	SdpCodecTemplate<CSdpAttributeField>::CloneArrayL(*iAttributeFields,
       
   677 											*aSdpDocument.iAttributeFields);
       
   678 	SdpCodecTemplate<CSdpMediaField>::CloneArrayL(*iMediaFields, 
       
   679 												*aSdpDocument.iMediaFields);
       
   680 	}
       
   681 
       
   682 // ---------------------------------------------------------------------------
       
   683 // CSdpDocument::ParseL
       
   684 // ---------------------------------------------------------------------------
       
   685 //
       
   686 void CSdpDocument::ParseL (const TDesC8& aText)
       
   687 	{
       
   688 	if(iTimeFields)
       
   689 		{
       
   690 		iTimeFields->ResetAndDestroy();
       
   691 		delete iTimeFields;
       
   692 		iTimeFields = 0;
       
   693 		}
       
   694 	iSdpCodecParseUtil = CSdpCodecParseUtil::NewL(iPool,aText,KErrSdpCodecDecode);
       
   695 	ParseSessionVersionL();
       
   696 	ParseSessionOwnerL();
       
   697 	ParseSessionNameL();
       
   698 	ParseSessionInformationL();
       
   699 	ParseUriL();
       
   700 	ParseEmailL();
       
   701 	ParsePhoneL();
       
   702 	ParseConnectionL();
       
   703 	ParseBandwidthL();
       
   704 	ParseTimeFieldL();
       
   705 	ParseZoneAdjustmentL();
       
   706 	ParseEncryptionKeyL();
       
   707 	ParseAttributeFieldL();
       
   708 	ParseMediaLevelL ();
       
   709 	}
       
   710 
       
   711 // ---------------------------------------------------------------------------
       
   712 // CSdpDocument::ParseSessionVersionL
       
   713 // ---------------------------------------------------------------------------
       
   714 //
       
   715 void CSdpDocument::ParseSessionVersionL()
       
   716 	{
       
   717 	iSdpVersion = 
       
   718 		iSdpCodecParseUtil->ParseSessionVersionL(KErrSdpCodecSessionField);
       
   719 	}
       
   720 
       
   721 // ---------------------------------------------------------------------------
       
   722 // CSdpDocument::ParseSessionOwnerL
       
   723 // ---------------------------------------------------------------------------
       
   724 //
       
   725 void CSdpDocument::ParseSessionOwnerL()
       
   726 	{
       
   727 	iSdpOriginField = iSdpCodecParseUtil->ParseSessionOwnerL(
       
   728 													KErrSdpCodecOriginField);
       
   729 	}
       
   730 
       
   731 // ---------------------------------------------------------------------------
       
   732 // CSdpDocument::ParseSessionNameL
       
   733 // ---------------------------------------------------------------------------
       
   734 //
       
   735 void CSdpDocument::ParseSessionNameL()
       
   736 	{
       
   737 	SetSessionNameL(iSdpCodecParseUtil->ParseSessionNameL(
       
   738 													KErrSdpCodecSessionField));
       
   739 	}
       
   740 
       
   741 // ---------------------------------------------------------------------------
       
   742 // CSdpDocument::ParseSessionInformationL
       
   743 // ---------------------------------------------------------------------------
       
   744 //
       
   745 void CSdpDocument::ParseSessionInformationL()
       
   746 	{
       
   747 	SetInfoL(iSdpCodecParseUtil->ParseInformationL(KErrSdpCodecInfoField));
       
   748 	}
       
   749 
       
   750 // ---------------------------------------------------------------------------
       
   751 // CSdpDocument::ParseUriL
       
   752 // ---------------------------------------------------------------------------
       
   753 //
       
   754 void CSdpDocument::ParseUriL()
       
   755 	{
       
   756 	SetUri(iSdpCodecParseUtil->ParseUriL(KErrSdpCodecUriField));
       
   757 	}
       
   758 
       
   759 // ---------------------------------------------------------------------------
       
   760 // CSdpDocument::ParseEmailL
       
   761 // ---------------------------------------------------------------------------
       
   762 //
       
   763 void CSdpDocument::ParseEmailL()
       
   764 	{
       
   765 	delete iEmailFields;
       
   766 	iEmailFields = NULL;
       
   767 	iEmailFields = iSdpCodecParseUtil->ParseEmailL(KErrSdpCodecEmailField);
       
   768 	}
       
   769 
       
   770 // ---------------------------------------------------------------------------
       
   771 // CSdpDocument::ParsePhoneL
       
   772 // ---------------------------------------------------------------------------
       
   773 //
       
   774 void CSdpDocument::ParsePhoneL()
       
   775 	{
       
   776 	delete iPhoneFields;
       
   777 	iPhoneFields = NULL;
       
   778 	iPhoneFields = iSdpCodecParseUtil->ParsePhoneL(KErrSdpCodecPhoneField);
       
   779 	}
       
   780 
       
   781 // ---------------------------------------------------------------------------
       
   782 // CSdpDocument::ParseConnectionL
       
   783 // ---------------------------------------------------------------------------
       
   784 //
       
   785 void CSdpDocument::ParseConnectionL()
       
   786 	{
       
   787 	iSdpConnectionField = 
       
   788 		iSdpCodecParseUtil->ParseConnectionL(KErrSdpCodecConnectionField);
       
   789 	}
       
   790 
       
   791 // ---------------------------------------------------------------------------
       
   792 // CSdpDocument::ParseBandwidthL
       
   793 // ---------------------------------------------------------------------------
       
   794 //
       
   795 void CSdpDocument::ParseBandwidthL()
       
   796 	{
       
   797 	delete iBandwidthFields;
       
   798 	iBandwidthFields = 0;
       
   799 	iBandwidthFields = 
       
   800 		iSdpCodecParseUtil->ParseBandwidthL(KErrSdpCodecBandwidthField);
       
   801 	}
       
   802 
       
   803 // ---------------------------------------------------------------------------
       
   804 // CSdpDocument::ParseTimeFieldL
       
   805 // ---------------------------------------------------------------------------
       
   806 //
       
   807 void CSdpDocument::ParseTimeFieldL()
       
   808 	{
       
   809 	delete iTimeFields;
       
   810 	iTimeFields = 0;
       
   811 	iTimeFields = iSdpCodecParseUtil->ParseTimeFieldL(KErrSdpCodecTimeField);
       
   812 	}
       
   813 
       
   814 // ---------------------------------------------------------------------------
       
   815 // CSdpDocument::ParseZoneAdjustmentL
       
   816 // ---------------------------------------------------------------------------
       
   817 //
       
   818 void CSdpDocument::ParseZoneAdjustmentL()
       
   819 	{
       
   820 	SetZoneAdjustmentsL(
       
   821 		iSdpCodecParseUtil->ParseZoneAdjustmentL(KErrSdpCodecZoneField));
       
   822 	}
       
   823 
       
   824 // ---------------------------------------------------------------------------
       
   825 // CSdpDocument::ParseEncryptionKeyL
       
   826 // ---------------------------------------------------------------------------
       
   827 //
       
   828 void CSdpDocument::ParseEncryptionKeyL()
       
   829 	{
       
   830 	SetKey(iSdpCodecParseUtil->ParseEncryptionKeyL(KErrSdpCodecKeyField));
       
   831 	}
       
   832 
       
   833 // ---------------------------------------------------------------------------
       
   834 // CSdpDocument::ParseAttributeFieldL
       
   835 // ---------------------------------------------------------------------------
       
   836 //
       
   837 void CSdpDocument::ParseAttributeFieldL()
       
   838 	{
       
   839 	delete iAttributeFields;
       
   840 	iAttributeFields = 0;
       
   841 	iAttributeFields = 
       
   842 		iSdpCodecParseUtil->ParseAttributeFieldL(KErrSdpCodecAttributeField);
       
   843 	}
       
   844 
       
   845 // ---------------------------------------------------------------------------
       
   846 // CSdpDocument::ParseMediaLevelL
       
   847 // ---------------------------------------------------------------------------
       
   848 //
       
   849 void CSdpDocument::ParseMediaLevelL()
       
   850 	{
       
   851 	delete iMediaFields;
       
   852 	iMediaFields = 0;
       
   853 	iMediaFields = iSdpCodecParseUtil->ParseMediaLevelL();
       
   854 	}
       
   855 
       
   856 // ---------------------------------------------------------------------------
       
   857 // CSdpDocument::ExternalizeDesCArrayL
       
   858 // ---------------------------------------------------------------------------
       
   859 //
       
   860 void CSdpDocument::ExternalizeDesCArrayL(CDesC8ArraySeg& aArray,
       
   861 						   RWriteStream& aStream) const
       
   862 	{
       
   863 	aStream.WriteUint32L (aArray.MdcaCount());
       
   864 	for (TInt i = 0;i < aArray.MdcaCount();i++)
       
   865 		{
       
   866 		aStream.WriteUint32L (aArray.MdcaPoint(i).Length());
       
   867 		aStream.WriteL(aArray.MdcaPoint(i));
       
   868 		}
       
   869 	}
       
   870 
       
   871 // ---------------------------------------------------------------------------
       
   872 // CSdpDocument::EncodeDesCArrayL
       
   873 // ---------------------------------------------------------------------------
       
   874 //
       
   875 void CSdpDocument::EncodeDesCArrayL(CDesC8ArraySeg& aArray, TInt aIndex,
       
   876 										RWriteStream& aStream) const
       
   877 	{
       
   878 	RStringF headername = 
       
   879 					iPool.StringF(aIndex, SdpCodecStringConstants::Table);
       
   880 	for (TInt i = 0;i < aArray.MdcaCount();i++)
       
   881 		{
       
   882 		if(aArray.MdcaPoint(i).Compare(KNullDesC8) != 0)
       
   883 			{
       
   884 			aStream.WriteL(headername.DesC());
       
   885 			aStream.WriteL(aArray.MdcaPoint(i));
       
   886 			aStream.WriteL(KCRLF);
       
   887 			}
       
   888 		}
       
   889 	}
       
   890 
       
   891 // ---------------------------------------------------------------------------
       
   892 // CSdpDocument::GetTokenFromStreamL
       
   893 // ---------------------------------------------------------------------------
       
   894 //
       
   895 TDesC8& CSdpDocument::GetTokenFromStreamL(RReadStream& aStream)
       
   896 	{
       
   897 	TUint32 tokenLength = aStream.ReadUint32L();
       
   898 	HBufC8* tmp = 0;
       
   899 	if (tokenLength > 0)
       
   900 		{
       
   901 		tmp = HBufC8::NewLC(tokenLength);
       
   902 		TPtr8 tokenptr(tmp->Des());
       
   903 		aStream.ReadL (tokenptr, tokenLength);
       
   904 		CleanupStack::Pop();//tmp
       
   905 		}
       
   906 	else
       
   907 		{
       
   908 		tmp = KNullDesC8().AllocL();
       
   909 		}
       
   910 	delete iToken;
       
   911 	iToken = tmp;
       
   912 	return *iToken;
       
   913 	}
       
   914