realtimenetprots/sipfw/SIP/Codec/src/CSIPContentTypeHeader.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name          : CSIPContentTypeHeader.cpp
       
    15 // Part of       : SIP Codec
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "sipcontenttypeheader.h"
       
    23 #include "CSIPContentTypeHeaderParams.h"
       
    24 #include "SIPSyntaxCheck.h"
       
    25 #include "sipcodecerr.h"
       
    26 #include "sipstrings.h"
       
    27 #include "sipstrconsts.h"
       
    28 #include "sipcodecutils.h"
       
    29 #include "_sipcodecdefs.h"
       
    30 
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CSIPContentTypeHeader::DecodeL
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 EXPORT_C CSIPContentTypeHeader* 
       
    37 CSIPContentTypeHeader::DecodeL (const TDesC8& aValue)
       
    38 	{
       
    39 	CSIPContentTypeHeader* header = new(ELeave)CSIPContentTypeHeader;
       
    40 	CleanupStack::PushL (header);
       
    41     header->ConstructL();
       
    42 	header->ParseL (aValue);
       
    43 	CleanupStack::Pop(header);
       
    44 	return header;
       
    45 	}
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CSIPContentTypeHeader::NewL
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C CSIPContentTypeHeader* CSIPContentTypeHeader::NewL(
       
    52     const TDesC8& aMediaType,
       
    53     const TDesC8& aMediaSubtype)
       
    54 	{
       
    55 	CSIPContentTypeHeader* self = 
       
    56 		CSIPContentTypeHeader::NewLC(aMediaType,aMediaSubtype);
       
    57 	CleanupStack::Pop(self);
       
    58 	return self;
       
    59 	}
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CSIPContentTypeHeader::NewLC
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 EXPORT_C CSIPContentTypeHeader* CSIPContentTypeHeader::NewLC(
       
    66     const TDesC8& aMediaType,
       
    67     const TDesC8& aMediaSubtype)
       
    68 	{
       
    69 	CSIPContentTypeHeader* self = new(ELeave)CSIPContentTypeHeader;
       
    70 	CleanupStack::PushL(self);
       
    71 	self->ConstructL(aMediaType,aMediaSubtype);
       
    72 	return self;
       
    73 	}
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CSIPContentTypeHeader::CSIPContentTypeHeader
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CSIPContentTypeHeader::CSIPContentTypeHeader()
       
    80  : CSIPParameterHeaderBase(';')
       
    81 	{
       
    82 	}
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CSIPContentTypeHeader::ConstructL
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CSIPContentTypeHeader::ConstructL ()
       
    89 	{
       
    90 	iParams = new(ELeave)CSIPContentTypeHeaderParams;
       
    91 	}
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CSIPContentTypeHeader::ConstructL
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CSIPContentTypeHeader::ConstructL (const TDesC8& aMediaType,
       
    98 										const TDesC8& aMediaSubtype)
       
    99 	{
       
   100     ConstructL ();
       
   101 	SetMediaTypeL (aMediaType);
       
   102 	SetMediaSubtypeL (aMediaSubtype);
       
   103 	}
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CSIPContentTypeHeader::ConstructL
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CSIPContentTypeHeader::ConstructL (const CSIPContentTypeHeader&
       
   110 										aContentTypeHeader)
       
   111 	{
       
   112 	SetMediaTypeL (aContentTypeHeader.MediaType());
       
   113 	SetMediaSubtypeL (aContentTypeHeader.MediaSubtype());
       
   114 	iParams = CSIPContentTypeHeaderParams::NewL(*(aContentTypeHeader.iParams));
       
   115 	}
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CSIPContentTypeHeader::~CSIPContentTypeHeader
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 EXPORT_C CSIPContentTypeHeader::~CSIPContentTypeHeader()
       
   122 	{
       
   123 	delete iParams;
       
   124 	delete iMediaSubtype;
       
   125 	delete iMediaType;
       
   126 	}
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CSIPContentTypeHeader::CloneL
       
   130 // From CSIPHeaderBase:
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 EXPORT_C CSIPHeaderBase* CSIPContentTypeHeader::CloneL () const
       
   134 	{
       
   135 	CSIPContentTypeHeader* clone = new(ELeave)CSIPContentTypeHeader;
       
   136 	CleanupStack::PushL(clone);
       
   137 	clone->ConstructL(*this);
       
   138 	CleanupStack::Pop(clone);
       
   139 	return clone;
       
   140 	}
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CSIPContentTypeHeader::MediaType
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 EXPORT_C const TDesC8& CSIPContentTypeHeader::MediaType () const
       
   147 	{
       
   148 	return *iMediaType;
       
   149 	}
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CSIPContentTypeHeader::SetMediaTypeL
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C void CSIPContentTypeHeader::SetMediaTypeL (const TDesC8& aMediaType)
       
   156 	{
       
   157     SIPCodecUtils::CheckAndSetValueL(iMediaType,
       
   158                                      aMediaType,
       
   159                                      KErrSipCodecContentTypeHeader);
       
   160 	}
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CSIPContentTypeHeader::MediaSubtype
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 EXPORT_C const TDesC8& CSIPContentTypeHeader::MediaSubtype () const
       
   167 	{
       
   168 	return *iMediaSubtype;
       
   169 	}
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CSIPContentTypeHeader::SetMediaSubtypeL
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C void 
       
   176 CSIPContentTypeHeader::SetMediaSubtypeL (const TDesC8& aMediaSubtype)
       
   177 	{
       
   178     SIPCodecUtils::CheckAndSetValueL(iMediaSubtype,
       
   179                                      aMediaSubtype,
       
   180                                      KErrSipCodecContentTypeHeader);
       
   181 	}
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CSIPContentTypeHeader::Name
       
   185 // From CSIPHeaderBase:
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 EXPORT_C RStringF CSIPContentTypeHeader::Name() const
       
   189 	{
       
   190 	return SIPStrings::StringF(SipStrConsts::EContentTypeHeader);
       
   191 	}
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CSIPContentTypeHeader::HasCompactName
       
   195 // From CSIPHeaderBase:
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 TBool CSIPContentTypeHeader::HasCompactName () const
       
   199 	{
       
   200 	return ETrue;
       
   201 	}
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CSIPContentTypeHeader::CompactName
       
   205 // From CSIPHeaderBase:
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 RStringF CSIPContentTypeHeader::CompactName () const
       
   209 	{
       
   210 	return SIPStrings::StringF(SipStrConsts::EContentTypeHeaderCompact);
       
   211 	}
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CSIPContentTypeHeader::InternalizeValueL
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 EXPORT_C CSIPHeaderBase* CSIPContentTypeHeader::InternalizeValueL(
       
   218     RReadStream& aReadStream)
       
   219 	{
       
   220 	CSIPContentTypeHeader* self = new(ELeave)CSIPContentTypeHeader;
       
   221 	CleanupStack::PushL(self);
       
   222 	self->DoInternalizeValueL(aReadStream);
       
   223 	CleanupStack::Pop(self);
       
   224 	return self;
       
   225 	}
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CSIPContentTypeHeader::ExternalizeValueL
       
   229 // From CSIPHeaderBase:
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 void CSIPContentTypeHeader::ExternalizeValueL(RWriteStream& aWriteStream) const
       
   233 	{
       
   234 	aWriteStream.WriteUint32L (iMediaType->Length());
       
   235 	aWriteStream.WriteL (*iMediaType);
       
   236 	
       
   237 	aWriteStream.WriteUint32L (iMediaSubtype->Length());
       
   238 	aWriteStream.WriteL (*iMediaSubtype);
       
   239 	
       
   240 	iParams->ExternalizeL (aWriteStream);
       
   241 	}
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CSIPContentTypeHeader::DoInternalizeValueL
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void CSIPContentTypeHeader::DoInternalizeValueL(RReadStream& aReadStream)
       
   248 	{
       
   249     iMediaType = SIPCodecUtils::ReadDescFromStreamL(aReadStream);
       
   250     iMediaSubtype = SIPCodecUtils::ReadDescFromStreamL(aReadStream);
       
   251 	iParams = CSIPContentTypeHeaderParams::InternalizeL (aReadStream);
       
   252 	}
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CSIPContentTypeHeader::PreferredPlaceInMessage
       
   256 // From CSIPHeaderBase:
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 CSIPHeaderBase::TPreferredPlace
       
   260 CSIPContentTypeHeader::PreferredPlaceInMessage () const
       
   261 	{
       
   262 	return CSIPHeaderBase::EBottom;
       
   263 	}
       
   264 	
       
   265 // -----------------------------------------------------------------------------
       
   266 // CSIPContentTypeHeader::BaseDecodeL
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 RPointerArray<CSIPHeaderBase> 
       
   270 CSIPContentTypeHeader::BaseDecodeL (const TDesC8& aValue)
       
   271 	{
       
   272 	CSIPContentTypeHeader* header = DecodeL(aValue);
       
   273 	CleanupStack::PushL (header);
       
   274 	RPointerArray<CSIPHeaderBase> headers;
       
   275 	User::LeaveIfError(headers.Append(header));
       
   276 	CleanupStack::Pop(header);
       
   277 	return headers;
       
   278 	}	
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CSIPContentTypeHeader::ToTextMandatoryPartLC
       
   282 // From CSIPParameterHeaderBase:
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 HBufC8* CSIPContentTypeHeader::ToTextMandatoryPartLC () const
       
   286     {
       
   287 	TUint encodedLength = iMediaType->Length() + 1; // SLASH
       
   288 	encodedLength += iMediaSubtype->Length(); 
       
   289 
       
   290 	HBufC8* encodingResult = HBufC8::NewLC (encodedLength);
       
   291 	TPtr8 encodingResultPtr = encodingResult->Des();
       
   292 
       
   293 	encodingResultPtr.Append(*iMediaType);
       
   294 	encodingResultPtr.Append('/'); // SLASH
       
   295 	encodingResultPtr.Append(*iMediaSubtype);
       
   296 
       
   297 	return encodingResult;
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CSIPContentTypeHeader::ParseMandatoryPartL
       
   302 // From CSIPParameterHeaderBase:
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 void CSIPContentTypeHeader::ParseMandatoryPartL (const TDesC8& aMandatoryPart)
       
   306     {
       
   307 	__ASSERT_ALWAYS (aMandatoryPart.Length() > 0,
       
   308 	                 User::Leave(KErrSipCodecContentTypeHeader));
       
   309 	
       
   310 	TLex8 lex(aMandatoryPart);
       
   311 	lex.SkipSpace();
       
   312 	TPtrC8 value(lex.Remainder());
       
   313 	
       
   314 	TInt slashPos = value.Locate('/');
       
   315 	if (slashPos <= 0 || slashPos >= value.Length()-1)
       
   316 		{
       
   317 		User::Leave (KErrSipCodecContentTypeHeader);
       
   318 		}
       
   319     
       
   320 	SetMediaTypeL (value.Left(slashPos));
       
   321     SetMediaSubtypeL (value.Mid(slashPos+1));
       
   322     }
       
   323     
       
   324 // -----------------------------------------------------------------------------
       
   325 // CSIPContentTypeHeader::Params
       
   326 // From CSIPParameterHeaderBase:
       
   327 // -----------------------------------------------------------------------------
       
   328 //
       
   329 const CSIPParamContainerBase& CSIPContentTypeHeader::Params () const
       
   330     {
       
   331     return *iParams; 
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CSIPContentTypeHeader::Params
       
   336 // From CSIPParameterHeaderBase:
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 CSIPParamContainerBase& CSIPContentTypeHeader::Params ()
       
   340     {
       
   341     return *iParams; 
       
   342     }