realtimenetprots/sipfw/SIP/Codec/src/CSIPContentDispositionHeader.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2004-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          : CSIPContentDispositionHeader.cpp
       
    15 // Part of       : SIP Codec
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "sipcontentdispositionheader.h"
       
    23 #include "CSIPHeaderGenericParams.h"
       
    24 #include "CSIPTokenizer.h"
       
    25 #include "sipcodecerr.h"
       
    26 #include "SIPSyntaxCheck.h"
       
    27 #include "sipstrings.h"
       
    28 #include "sipstrconsts.h"
       
    29 #include "sipcodecutils.h"
       
    30 #include "_sipcodecdefs.h"
       
    31 
       
    32 
       
    33 // ----------------------------------------------------------------------------
       
    34 // CSIPContentDispositionHeader::DecodeL
       
    35 // ----------------------------------------------------------------------------
       
    36 //
       
    37 EXPORT_C CSIPContentDispositionHeader* 
       
    38 CSIPContentDispositionHeader::DecodeL (const TDesC8& aValue)
       
    39 	{
       
    40 	CSIPContentDispositionHeader* contentDispositionHeader = 
       
    41 		new(ELeave) CSIPContentDispositionHeader;
       
    42     CleanupStack::PushL(contentDispositionHeader);
       
    43     contentDispositionHeader->ConstructL();
       
    44 	contentDispositionHeader->ParseL(aValue);
       
    45 	CleanupStack::Pop(contentDispositionHeader);
       
    46 	return contentDispositionHeader;
       
    47 	}
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 // CSIPContentDispositionHeader::NewL
       
    51 // ----------------------------------------------------------------------------
       
    52 //
       
    53 EXPORT_C CSIPContentDispositionHeader* CSIPContentDispositionHeader::NewL(
       
    54     const TDesC8& aDispType)
       
    55 	{
       
    56 	CSIPContentDispositionHeader* self = 
       
    57 		CSIPContentDispositionHeader::NewLC(aDispType);
       
    58 	CleanupStack::Pop(self);
       
    59 	return self;
       
    60 	}
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // CSIPContentDispositionHeader::NewLC
       
    64 // ----------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CSIPContentDispositionHeader* 
       
    67 CSIPContentDispositionHeader::NewLC(const TDesC8& aDispType)
       
    68 	{
       
    69 	CSIPContentDispositionHeader* self=
       
    70 		new(ELeave) CSIPContentDispositionHeader();
       
    71 	CleanupStack::PushL(self);
       
    72 	self->ConstructL(aDispType);
       
    73 	return self;
       
    74 	}
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // CSIPContentDispositionHeader::CSIPContentDispositionHeader
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 CSIPContentDispositionHeader::CSIPContentDispositionHeader()
       
    81 :   CSIPParameterHeaderBase(';')
       
    82 	{
       
    83 	}
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // CSIPContentDispositionHeader::ConstructL
       
    87 // ----------------------------------------------------------------------------
       
    88 //
       
    89 void CSIPContentDispositionHeader::ConstructL()
       
    90 	{
       
    91 	iParams = new(ELeave)CSIPHeaderGenericParams;
       
    92 	}
       
    93 
       
    94 // ----------------------------------------------------------------------------
       
    95 // CSIPContentDispositionHeader::ConstructL
       
    96 // ----------------------------------------------------------------------------
       
    97 //
       
    98 void CSIPContentDispositionHeader::ConstructL (const TDesC8& aDispType)
       
    99 	{
       
   100 	ConstructL ();
       
   101 	SetDispTypeL (aDispType);
       
   102 	}
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // CSIPContentDispositionHeader::ConstructL
       
   106 // ----------------------------------------------------------------------------
       
   107 //
       
   108 void 
       
   109 CSIPContentDispositionHeader::ConstructL (const TDesC8& aDispType, 
       
   110 										  const TDesC8& aHandlingParam)
       
   111 	{
       
   112 	ConstructL ();
       
   113 	SetDispTypeL(aDispType);
       
   114     iParams->SetParamL(
       
   115         SIPStrings::StringF(SipStrConsts::EHandling),aHandlingParam);
       
   116 	}
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // CSIPContentDispositionHeader::ConstructL
       
   120 // ----------------------------------------------------------------------------
       
   121 //
       
   122 void 
       
   123 CSIPContentDispositionHeader::ConstructL (const CSIPContentDispositionHeader& 
       
   124 										  aSIPContentDispositionHeader)
       
   125 	{
       
   126 	iParams =
       
   127 		CSIPHeaderGenericParams::NewL(
       
   128 									*(aSIPContentDispositionHeader.iParams));
       
   129 	SetDispTypeL(aSIPContentDispositionHeader.DispType());
       
   130 	}
       
   131 
       
   132 // ----------------------------------------------------------------------------
       
   133 // CSIPContentDispositionHeader::~CSIPContentDispositionHeader
       
   134 // ----------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C CSIPContentDispositionHeader::~CSIPContentDispositionHeader()
       
   137 	{
       
   138 	delete iParams;
       
   139 	delete iDispType;
       
   140 	}
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // CSIPContentDispositionHeader::CloneL
       
   144 // From CSIPHeaderBase:
       
   145 // ----------------------------------------------------------------------------
       
   146 //
       
   147 EXPORT_C CSIPHeaderBase* CSIPContentDispositionHeader::CloneL () const
       
   148 	{
       
   149     CSIPContentDispositionHeader* clone = 
       
   150         new (ELeave) CSIPContentDispositionHeader;
       
   151     CleanupStack::PushL(clone);
       
   152     clone->ConstructL(*this);
       
   153     CleanupStack::Pop(clone);
       
   154     return clone;
       
   155 	}
       
   156 
       
   157 // ----------------------------------------------------------------------------
       
   158 // CSIPContentDispositionHeader::Name
       
   159 // From CSIPHeaderBase:
       
   160 // ----------------------------------------------------------------------------
       
   161 //
       
   162 EXPORT_C RStringF CSIPContentDispositionHeader::Name () const
       
   163 	{
       
   164     return SIPStrings::StringF(SipStrConsts::EContentDispositionHeader);
       
   165 	}
       
   166 
       
   167 // ----------------------------------------------------------------------------
       
   168 // CSIPContentDispositionHeader::SetDispTypeL
       
   169 // ----------------------------------------------------------------------------
       
   170 //
       
   171 EXPORT_C void 
       
   172 CSIPContentDispositionHeader::SetDispTypeL (const TDesC8& aDispType)
       
   173 	{
       
   174     SIPCodecUtils::CheckAndSetValueL(iDispType,
       
   175                                      aDispType,
       
   176                                      KErrSipCodecContentDispositionHeader);
       
   177 	}
       
   178 
       
   179 // ----------------------------------------------------------------------------
       
   180 // CSIPContentDispositionHeader::DispType
       
   181 // ----------------------------------------------------------------------------
       
   182 //
       
   183 EXPORT_C const TDesC8& CSIPContentDispositionHeader::DispType() const
       
   184 	{
       
   185 	if (iDispType != 0) 
       
   186 		{
       
   187 		return *iDispType;
       
   188 		}
       
   189 	return KNullDesC8;
       
   190 	}
       
   191 
       
   192 // ----------------------------------------------------------------------------
       
   193 // CSIPContentDispositionHeaderr::ToTextMandatoryPartLC
       
   194 // From CSIPHeaderBase:
       
   195 // ----------------------------------------------------------------------------
       
   196 //
       
   197 HBufC8* CSIPContentDispositionHeader::ToTextMandatoryPartLC () const
       
   198 	{
       
   199 	TUint encodedLength = 0;
       
   200 	if(iDispType != 0)
       
   201 		{
       
   202 		encodedLength += iDispType->Length(); 
       
   203 		}
       
   204 
       
   205 	HBufC8* encodedHeader = HBufC8::NewLC (encodedLength);
       
   206 	TPtr8 encodedHeaderPtr = encodedHeader->Des();
       
   207 
       
   208 	encodedHeaderPtr.Append(*iDispType);
       
   209 	return encodedHeader;
       
   210 	}
       
   211 
       
   212 // ----------------------------------------------------------------------------
       
   213 // CSIPContentDispositionHeader::InternalizeValueL
       
   214 // ----------------------------------------------------------------------------
       
   215 //
       
   216 EXPORT_C CSIPHeaderBase* CSIPContentDispositionHeader::InternalizeValueL(
       
   217     RReadStream& aReadStream)
       
   218 	{
       
   219 	CSIPContentDispositionHeader* self = 
       
   220 		new(ELeave)CSIPContentDispositionHeader;
       
   221 	CleanupStack::PushL(self);
       
   222 	self->DoInternalizeValueL(aReadStream);
       
   223 	CleanupStack::Pop(self);
       
   224 	return self;
       
   225 	}
       
   226 
       
   227 // ----------------------------------------------------------------------------
       
   228 // CSIPContentDispositionHeader::DoInternalizeValueL
       
   229 // ----------------------------------------------------------------------------
       
   230 //
       
   231 void CSIPContentDispositionHeader::DoInternalizeValueL(
       
   232     RReadStream& aReadStream)
       
   233 	{
       
   234     iDispType = SIPCodecUtils::ReadDescFromStreamL(aReadStream);
       
   235 	iParams = CSIPHeaderGenericParams::InternalizeL (aReadStream);
       
   236 	}	
       
   237 
       
   238 // ----------------------------------------------------------------------------
       
   239 // CSIPContentDispositionHeader::ExternalizeValueL
       
   240 // From CSIPHeaderBase:
       
   241 // ----------------------------------------------------------------------------
       
   242 //
       
   243 void CSIPContentDispositionHeader::ExternalizeValueL(
       
   244     RWriteStream& aWriteStream) const
       
   245 	{
       
   246 	aWriteStream.WriteUint32L (iDispType->Length());
       
   247 	if (iDispType->Length() > 0)
       
   248 		{
       
   249 		aWriteStream.WriteL (DispType());
       
   250 		}
       
   251 	iParams->ExternalizeL (aWriteStream);
       
   252 	}
       
   253 
       
   254 // ----------------------------------------------------------------------------
       
   255 // CSIPContentDispositionHeader::PreferredPlaceInMessage
       
   256 // From CSIPHeaderBase:
       
   257 // ----------------------------------------------------------------------------
       
   258 //
       
   259 CSIPHeaderBase::TPreferredPlace
       
   260 CSIPContentDispositionHeader::PreferredPlaceInMessage () const
       
   261 	{
       
   262 	return CSIPHeaderBase::EBottom;
       
   263 	}
       
   264 
       
   265 // ----------------------------------------------------------------------------
       
   266 // CSIPContentDispositionHeader::BaseDecodeL
       
   267 // From CSIPHeaderBase:
       
   268 // ----------------------------------------------------------------------------
       
   269 //
       
   270 RPointerArray<CSIPHeaderBase> 
       
   271 CSIPContentDispositionHeader::BaseDecodeL(const TDesC8& aValue)
       
   272     {
       
   273 	CSIPContentDispositionHeader* contentDispositionHeader = 
       
   274 		new(ELeave) CSIPContentDispositionHeader;
       
   275     CleanupStack::PushL(contentDispositionHeader);
       
   276     contentDispositionHeader->ConstructL();
       
   277 	contentDispositionHeader->ParseL (aValue);
       
   278 	RPointerArray<CSIPHeaderBase> headerArray;
       
   279 	User::LeaveIfError (headerArray.Append(contentDispositionHeader));
       
   280 	CleanupStack::Pop(); // contentDispositionHeader
       
   281 	return headerArray;
       
   282     }
       
   283 
       
   284 // ----------------------------------------------------------------------------
       
   285 // CSIPContentDispositionHeader::Params
       
   286 // From CSIPParameterHeaderBase:
       
   287 // ----------------------------------------------------------------------------
       
   288 //
       
   289 const CSIPParamContainerBase& CSIPContentDispositionHeader::Params () const
       
   290     {
       
   291     return *iParams; 
       
   292     }
       
   293 
       
   294 // ----------------------------------------------------------------------------
       
   295 // CSIPContentDispositionHeader::Params
       
   296 // From CSIPParameterHeaderBase:
       
   297 // ----------------------------------------------------------------------------
       
   298 //
       
   299 CSIPParamContainerBase& CSIPContentDispositionHeader::Params ()
       
   300     {
       
   301     return *iParams; 
       
   302     }
       
   303 
       
   304 // ----------------------------------------------------------------------------
       
   305 // CSIPContentDispositionHeader::ParseMandatoryPartL
       
   306 // ----------------------------------------------------------------------------
       
   307 //
       
   308 void 
       
   309 CSIPContentDispositionHeader::ParseMandatoryPartL(const TDesC8& aMandatoryPart)
       
   310 	{
       
   311 	__ASSERT_ALWAYS (aMandatoryPart.Length() > 0, 
       
   312 		User::Leave (KErrSipCodecContentDispositionHeader));
       
   313 	TLex8 lex(aMandatoryPart);
       
   314 	lex.SkipSpace();
       
   315 	SetDispTypeL(lex.Remainder());
       
   316 	}