realtimenetprots/sipfw/SIP/Codec/src/CSIPAuthenticateHeaderBase.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2006-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          : CSIPAuthenticateHeaderBase.cpp
       
    15 // Part of       : SIP Codec
       
    16 // Version       : SIP/5.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "sipauthenticateheaderbase.h"
       
    22 #include "CSIPAuthenticateHeaderParams.h"
       
    23 #include "CSIPTokenizer.h"
       
    24 #include "sipcodecerr.h"
       
    25 #include "SIPSyntaxCheck.h"
       
    26 #include "sipstrings.h"
       
    27 #include "sipstrconsts.h"
       
    28 #include "sipcodecutils.h"
       
    29 #include "_sipcodecdefs.h"
       
    30 
       
    31 
       
    32 // ----------------------------------------------------------------------------
       
    33 // CSIPAuthenticateHeaderBase::~CSIPAuthenticateHeaderBase
       
    34 // ----------------------------------------------------------------------------
       
    35 //
       
    36 EXPORT_C CSIPAuthenticateHeaderBase::~CSIPAuthenticateHeaderBase()
       
    37 	{
       
    38 	delete iParams;
       
    39 	}
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // CSIPAuthenticateHeaderBase::CSIPAuthenticateHeaderBase
       
    43 // ----------------------------------------------------------------------------
       
    44 //
       
    45 CSIPAuthenticateHeaderBase::CSIPAuthenticateHeaderBase()
       
    46 	{
       
    47 	}
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 // CSIPAuthenticateHeaderBase::ConstructL
       
    51 // ----------------------------------------------------------------------------
       
    52 //
       
    53 void CSIPAuthenticateHeaderBase::ConstructL()
       
    54 	{
       
    55 	iParams = new(ELeave)CSIPAuthenticateHeaderParams;
       
    56 	}	
       
    57 	
       
    58 // ----------------------------------------------------------------------------
       
    59 // CSIPAuthenticateHeaderBase::ConstructL
       
    60 // ----------------------------------------------------------------------------
       
    61 //
       
    62 void CSIPAuthenticateHeaderBase::ConstructL(
       
    63     const CSIPAuthenticateHeaderBase& aHeader)
       
    64 	{
       
    65 	CSIPAuthHeaderBase::ConstructL(aHeader.AuthScheme());
       
    66 	iParams = CSIPAuthenticateHeaderParams::NewL(*(aHeader.iParams));
       
    67 	}	
       
    68     
       
    69 // ----------------------------------------------------------------------------
       
    70 // CSIPAuthenticateHeaderBase::Params
       
    71 // From CSIPParameterHeaderBase:
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 const CSIPParamContainerBase& CSIPAuthenticateHeaderBase::Params () const
       
    75     {
       
    76     return *iParams; 
       
    77     }
       
    78 
       
    79 // ----------------------------------------------------------------------------
       
    80 // CSIPAuthenticateHeaderBase::Params
       
    81 // From CSIPParameterHeaderBase:
       
    82 // ----------------------------------------------------------------------------
       
    83 //
       
    84 CSIPParamContainerBase& CSIPAuthenticateHeaderBase::Params ()
       
    85     {
       
    86     return *iParams; 
       
    87     }
       
    88 
       
    89 // ----------------------------------------------------------------------------
       
    90 // CSIPAuthenticateHeaderBase::HasQopValue
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 EXPORT_C TBool CSIPAuthenticateHeaderBase::HasQopValueL(
       
    94     const TDesC8& aValue) const
       
    95     { 
       
    96 	TBool found = EFalse;
       
    97 	RStringF qop = SIPStrings::StringF(SipStrConsts::EQop);
       
    98     TPtrC8 qopWithoutQuotes;
       
    99     SIPCodecUtils::ValueWithoutQuotes(
       
   100         iParams->ParamValue(qop).DesC(), qopWithoutQuotes);		
       
   101 	if(qopWithoutQuotes.Length() > 0 && aValue.Length() > 0)
       
   102 		{
       
   103 		CSIPTokenizer* tokenizer = CSIPTokenizer::NewLC(qopWithoutQuotes, ',');
       
   104 		for (TInt i=0; i < tokenizer->Tokens().Count() && !found; i++)
       
   105 			{
       
   106 			HBufC8* trimmedToken = tokenizer->Tokens()[i].AllocLC();
       
   107 			trimmedToken->Des().Trim();
       
   108 			if(aValue == *trimmedToken)
       
   109 				{
       
   110 				found = ETrue;
       
   111 				}
       
   112 			CleanupStack::PopAndDestroy(trimmedToken);
       
   113 			}
       
   114 		CleanupStack::PopAndDestroy(tokenizer);
       
   115 		}
       
   116 	return found;
       
   117 	}
       
   118 
       
   119 // ----------------------------------------------------------------------------
       
   120 // CSIPAuthenticateHeaderBase::ExternalizeSupported
       
   121 // From CSIPHeaderBase:
       
   122 // ----------------------------------------------------------------------------
       
   123 //
       
   124 EXPORT_C TBool CSIPAuthenticateHeaderBase::ExternalizeSupported() const
       
   125 	{
       
   126 	return ETrue;
       
   127 	}
       
   128 		
       
   129 // ----------------------------------------------------------------------------
       
   130 // CSIPAuthenticateHeaderBase::ExternalizeValueL
       
   131 // ----------------------------------------------------------------------------
       
   132 //
       
   133 void CSIPAuthenticateHeaderBase::ExternalizeValueL(
       
   134     RWriteStream& aWriteStream) const
       
   135 	{
       
   136 	TPtrC8 authScheme(AuthScheme().DesC());
       
   137 	aWriteStream.WriteUint32L(authScheme.Length());
       
   138 	aWriteStream.WriteL(authScheme);
       
   139 	iParams->ExternalizeL(aWriteStream);	
       
   140 	}
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // CSIPAuthenticateHeaderBase::DoInternalizeValueL
       
   144 // ----------------------------------------------------------------------------
       
   145 //
       
   146 void CSIPAuthenticateHeaderBase::DoInternalizeValueL(RReadStream& aReadStream)
       
   147 	{
       
   148     HBufC8* authScheme = SIPCodecUtils::ReadDescFromStreamL(aReadStream);
       
   149     CleanupStack::PushL(authScheme);
       
   150     SetAuthSchemeL(*authScheme);
       
   151     CleanupStack::PopAndDestroy(authScheme);
       
   152 	iParams = CSIPAuthenticateHeaderParams::InternalizeL (aReadStream);	
       
   153 	}