applayerprotocols/httpexamples/cookies/inc/ccookie.inl
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2001-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 //
       
    15 
       
    16 #include <httpstringconstants.h>
       
    17 
       
    18 inline CCookie* CCookie::NewL(RStringPool aStringPool, RString aName, RString aValue, TBool aCookie2)
       
    19 	{
       
    20 	CCookie* cookie = new(ELeave)CCookie(aStringPool, aCookie2);
       
    21 	CleanupStack::PushL(cookie);
       
    22 	cookie->ConstructL(aName, aValue);
       
    23 	CleanupStack::Pop(cookie);
       
    24 	return cookie;
       
    25 	}
       
    26 
       
    27 inline CCookie::CCookie(RStringPool aStringPool, TBool aCookie2) :
       
    28 	iStringPool(aStringPool),
       
    29 	iSetCookie2(aCookie2)
       
    30 	{
       
    31 	}
       
    32 
       
    33 inline CCookie::~CCookie()
       
    34 	{
       
    35 	// go through each attribute closing any attribute strings	
       
    36 	const TInt numAttributes= iAttributes.Count();
       
    37 	for (TInt ii=0; ii<numAttributes; ++ii)
       
    38 		CloseAttribute(iAttributes[ii]);
       
    39 	iAttributes.Reset();
       
    40 	}
       
    41 
       
    42 inline void CCookie::CloseAttribute(CCookie::TCookieAttribute aCookieAttribute)
       
    43 	{
       
    44 	THTTPHdrVal attributeVal = aCookieAttribute.iValue;
       
    45 	if (attributeVal.Type() == THTTPHdrVal::KStrVal)
       
    46 		attributeVal.Str().Close();
       
    47 	else if (attributeVal.Type() == THTTPHdrVal::KStrFVal)
       
    48 		attributeVal.StrF().Close();	
       
    49 	}
       
    50 
       
    51 inline void CCookie::ConstructL(RString aName, RString aValue)
       
    52 	{
       
    53 	THTTPHdrVal value(aName);
       
    54 	SetAttributeL(EName, value);
       
    55 	value.SetStr(aValue);
       
    56 	SetAttributeL(EValue, value);
       
    57 	}
       
    58 
       
    59 inline void CCookie::SetAttributeL(CCookie::TCookieAttributeName aAttributeName, 
       
    60 									 THTTPHdrVal aAttributeVal)
       
    61 	{
       
    62 	TCookieAttribute attribute;
       
    63 	TInt index = FindAttribute(aAttributeName, attribute);
       
    64 	if(index != KErrNotFound)
       
    65 		{
       
    66 		CloseAttribute(attribute);
       
    67 		iAttributes.Remove(index);
       
    68 		}
       
    69 
       
    70 	TCookieAttribute newAttribute(aAttributeName, aAttributeVal);
       
    71 	User::LeaveIfError(iAttributes.Append(newAttribute));
       
    72 	}
       
    73 
       
    74 inline TInt CCookie::Attribute(CCookie::TCookieAttributeName aAttributeName, 
       
    75 								 THTTPHdrVal& aAttributeVal) const
       
    76 	{
       
    77 	TCookieAttribute attribute;
       
    78 	if(FindAttribute(aAttributeName, attribute) != KErrNotFound)
       
    79 		{
       
    80 		aAttributeVal = attribute.iValue;
       
    81 		return KErrNone;
       
    82 		}
       
    83 
       
    84 	return KErrNotFound;
       
    85 	}
       
    86 
       
    87 inline TInt CCookie::FindAttribute(TCookieAttributeName aAttributeName, TCookieAttribute& aAttribute) const
       
    88 	{
       
    89 	const TInt numAttributes = iAttributes.Count();
       
    90 	for (TInt index = 0; index<numAttributes; ++index)
       
    91 		{
       
    92 		if (iAttributes[index].iName == aAttributeName)
       
    93 			{
       
    94 			aAttribute = iAttributes[index];
       
    95 			return index;
       
    96 			}
       
    97 		}
       
    98 
       
    99 	return KErrNotFound;
       
   100 	}
       
   101 
       
   102 inline TBool CCookie::FromCookie2() const
       
   103 	{
       
   104 	return iSetCookie2;
       
   105 	}
       
   106 
       
   107 inline CCookie::TCookieAttribute::TCookieAttribute(TCookieAttributeName aName, THTTPHdrVal aHdrVal) :
       
   108 iName(aName)
       
   109 	{
       
   110 	iValue = aHdrVal.Copy();
       
   111 	}
       
   112 
       
   113 inline CCookie::TCookieAttribute::TCookieAttribute()
       
   114 	{
       
   115 	}
       
   116