realtimenetprots/sipfw/SIP/Codec/src/CSIPAuthHeaderBase.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          : CSIPAuthHeaderBase.cpp
       
    15 // Part of       : SIP Codec
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "sipauthheaderbase.h"
       
    22 #include "CSIPParamContainerBase.h"
       
    23 #include "CSIPTokenizer.h"
       
    24 #include "sipcodecerr.h"
       
    25 #include "sipstrings.h"
       
    26 #include "sipstrconsts.h"
       
    27 #include "sipcodecutils.h"
       
    28 #include "_sipcodecdefs.h"
       
    29 
       
    30 // ----------------------------------------------------------------------------
       
    31 // CSIPAuthHeaderBase::CSIPAuthHeaderBase
       
    32 // ----------------------------------------------------------------------------
       
    33 //
       
    34 CSIPAuthHeaderBase::CSIPAuthHeaderBase()
       
    35 :iSeparator(',')
       
    36 	{
       
    37 	}
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // CSIPAuthHeaderBase::ConstructL
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 void CSIPAuthHeaderBase::ConstructL(RStringF aAuthScheme)
       
    44 	{
       
    45 	SetAuthSchemeL(aAuthScheme.DesC());
       
    46 	}
       
    47 
       
    48 // ----------------------------------------------------------------------------
       
    49 // CSIPAuthHeaderBase::~CSIPAuthHeaderBase
       
    50 // ----------------------------------------------------------------------------
       
    51 //
       
    52 EXPORT_C CSIPAuthHeaderBase::~CSIPAuthHeaderBase()
       
    53 	{
       
    54 	iAuthScheme.Close();
       
    55 	}
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // CSIPAuthHeaderBase::AuthScheme
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C RStringF CSIPAuthHeaderBase::AuthScheme() const
       
    62 	{
       
    63 	return iAuthScheme;
       
    64 	}
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // CSIPAuthHeaderBase::SetParamAndAddQuotesL
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 EXPORT_C void CSIPAuthHeaderBase::SetParamAndAddQuotesL(RStringF aName,
       
    71                                                         const TDesC8& aValue)
       
    72 	{
       
    73     const TInt KQuotesLength = 2;
       
    74 	HBufC8* tmp = HBufC8::NewLC(aValue.Length()+KQuotesLength);
       
    75 	TPtr8 tmpPtr(tmp->Des());
       
    76 	tmpPtr.Append('"');
       
    77 	tmpPtr.Append(aValue);
       
    78 	tmpPtr.Append('"');	
       
    79 	Params().SetParamL(aName,tmpPtr);
       
    80 	CleanupStack::PopAndDestroy(tmp);
       
    81 	}
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CSIPAuthHeaderBase::ExternalizeSupported
       
    85 // From CSIPHeaderBase:
       
    86 // ----------------------------------------------------------------------------
       
    87 //
       
    88 EXPORT_C TBool CSIPAuthHeaderBase::ExternalizeSupported() const
       
    89 	{
       
    90 	return EFalse;
       
    91 	}
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // CSIPAuthHeaderBase::EncodeMultipleToOneLine
       
    95 // From CSIPHeaderBase:
       
    96 // ----------------------------------------------------------------------------
       
    97 //
       
    98 TBool CSIPAuthHeaderBase::EncodeMultipleToOneLine() const
       
    99 	{
       
   100 	return EFalse;	
       
   101 	}
       
   102 
       
   103 // ----------------------------------------------------------------------------
       
   104 // CSIPAuthHeaderBase::MoreThanOneAllowed
       
   105 // From CSIPHeaderBase:
       
   106 // ----------------------------------------------------------------------------
       
   107 //		
       
   108 TBool CSIPAuthHeaderBase::MoreThanOneAllowed() const
       
   109 	{
       
   110 	return ETrue;	
       
   111 	}
       
   112 
       
   113 // ----------------------------------------------------------------------------
       
   114 // CSIPAuthHeaderBase::PreferredPlaceInMessage
       
   115 // From CSIPHeaderBase:
       
   116 // ----------------------------------------------------------------------------
       
   117 //
       
   118 CSIPHeaderBase::TPreferredPlace
       
   119 CSIPAuthHeaderBase::PreferredPlaceInMessage () const
       
   120 	{
       
   121 	return CSIPHeaderBase::EMiddleBottom;
       
   122 	}
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CSIPAuthHeaderBase::ToTextValueL
       
   126 // From CSIPHeaderBase:
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 HBufC8* CSIPAuthHeaderBase::ToTextValueL() const
       
   130 	{
       
   131 	TUint encodedLength = iAuthScheme.DesC().Length(); 
       
   132 
       
   133 	HBufC8* encodedParams = Params().ToTextLC();
       
   134 	if (Params().ParamCount() > 0)
       
   135 		{
       
   136 		encodedLength += 1; // separator		
       
   137 		encodedLength += encodedParams->Length();
       
   138 		}
       
   139 
       
   140 	HBufC8* encodingResult = HBufC8::NewL (encodedLength);
       
   141 	TPtr8 encodingResultPtr = encodingResult->Des();
       
   142 
       
   143 	encodingResultPtr.Append(iAuthScheme.DesC());
       
   144 
       
   145 	if (Params().ParamCount() > 0)
       
   146 		{
       
   147 		encodingResultPtr.Append(' '); // Separate Scheme from other values
       
   148 		encodingResultPtr.Append(*encodedParams);
       
   149 		}
       
   150 
       
   151 	CleanupStack::PopAndDestroy(encodedParams);
       
   152 	return encodingResult;
       
   153 	}
       
   154 
       
   155 // ----------------------------------------------------------------------------
       
   156 // CSIPAuthHeaderBase::SetAuthSchemeL
       
   157 // ----------------------------------------------------------------------------
       
   158 //
       
   159 void CSIPAuthHeaderBase::SetAuthSchemeL(const TDesC8& aAuthScheme)
       
   160 	{		
       
   161     RStringF tmp = 
       
   162         SIPCodecUtils::CheckAndCreateTokenL(
       
   163             aAuthScheme,KErrSipCodecAuthScheme);
       
   164 	iAuthScheme.Close();
       
   165     iAuthScheme = tmp;
       
   166 	}
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CSIPAuthHeaderBase::ParseL
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CSIPAuthHeaderBase::ParseL(const TDesC8& aValue)
       
   173 	{
       
   174 	TLex8 lex(aValue);
       
   175 	lex.SkipSpace();
       
   176 	TPtrC8 mandatoryPart(lex.NextToken());
       
   177 	if (mandatoryPart.Length() < 1) 
       
   178 		{
       
   179 		User::Leave (KErrSipCodecAuthScheme);
       
   180 		}
       
   181     SetAuthSchemeL(mandatoryPart);
       
   182     lex.SkipSpace();
       
   183     Params().ParseL(lex.Remainder());
       
   184 	}
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CSIPAuthHeaderBase::HasParam
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 EXPORT_C TBool CSIPAuthHeaderBase::HasParam(RStringF aName) const
       
   191 	{
       
   192 	return Params().HasParam(aName);
       
   193 	}
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CSIPAuthHeaderBase::ParamValue
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 EXPORT_C RStringF CSIPAuthHeaderBase::ParamValue(RStringF aName) const
       
   200 	{
       
   201 	return Params().ParamValue(aName);
       
   202 	}
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CSIPAuthHeaderBase::DesParamValue
       
   206 // -----------------------------------------------------------------------------
       
   207 //	
       
   208 EXPORT_C const TDesC8& CSIPAuthHeaderBase::DesParamValue(RStringF aName) const
       
   209     {
       
   210     return Params().DesParamValue(aName);
       
   211     }		
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CSIPAuthHeaderBase::SetParamL
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 EXPORT_C void CSIPAuthHeaderBase::SetParamL(
       
   218     RStringF aName,
       
   219     RStringF aValue)
       
   220 	{
       
   221 	Params().SetParamL(aName,aValue);
       
   222 	}
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CSIPAuthHeaderBase::SetDesParamL
       
   226 // -----------------------------------------------------------------------------
       
   227 //	
       
   228 EXPORT_C void CSIPAuthHeaderBase::SetDesParamL(
       
   229     RStringF aName,
       
   230     const TDesC8& aValue)
       
   231     {
       
   232     Params().SetDesParamL(aName,aValue);
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CSIPAuthHeaderBase::DeleteParam
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 EXPORT_C void CSIPAuthHeaderBase::DeleteParam(RStringF aName)
       
   240 	{
       
   241 	Params().DeleteParam(aName);
       
   242 	}