applayerprotocols/httpexamples/cookies/inc/ccookie.h
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 #ifndef		__CCOOKIE_H__
       
    17 #define		__CCOOKIE_H__
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <stringpool.h>
       
    21 #include <http/thttphdrval.h>
       
    22 
       
    23 /** Class to store the data that makes up a cookie
       
    24 */
       
    25 class CCookie : public CBase
       
    26 	{
       
    27 public:
       
    28 	/** Enumeration of all the elements of data that make up a cookie
       
    29 	*/
       
    30 	enum TCookieAttributeName
       
    31 		{
       
    32 		EName,			// Name of the cookie - mandatory
       
    33 		EValue,			// Value associated with the name - mandatory
       
    34 		EComment,		// Comment which can be displayed to the user
       
    35 		ECommentURI,	// A URI which can be visited for more information
       
    36 		EDiscard,		// Flag indicating that the cookie should be discarded
       
    37 		EDomain,		// Domain which this cookie applies to
       
    38 		EMaxAge,		// Age after which this cookie should be deleted
       
    39 		EPath,			// Path which this cookie applies to
       
    40 		EPort,			// Port numbers that this cookie applies to
       
    41 		ESecure,		// Flag indicating this cookie should only be used for secure transactions
       
    42 		EVersion,		// Version of style of cookie
       
    43 		EExpires,		// Time after which this cookie should be deleted - Netscape cookies only
       
    44 		};
       
    45 
       
    46 	/** Standard C class construction method
       
    47 		@param	aStringPool	A string pool to be used by this cookie
       
    48 		@param	aName		Name attribute for this cookie
       
    49 		@param	aValue		Value attribute for this cookie
       
    50 		@param	aCookie2	Flag indicating if this cookie was received in a SetCookie2 header
       
    51 		@return	Pointer to a fully constructed CCookie
       
    52 	*/
       
    53 	static CCookie* NewL(RStringPool aStringPool, RString aName, RString aValue, TBool aCookie2);
       
    54 
       
    55 	/** Standard destructor
       
    56 	*/
       
    57 	~CCookie();
       
    58 	
       
    59 	/** SetAttributeL sets an attribute on the cookie. 
       
    60 		Adding an attribute where one exists will replace the existing one
       
    61 		This function may leave with a system wide error code if the type of the value is not correct
       
    62 		or if the attempt to append the attribute to an internal list fails.
       
    63 		@param aAttributeName identifies the attribute 
       
    64 		@param aAttributeVal the value being set
       
    65 		@leave KErrNoMemory if there is not enough memory
       
    66 	*/
       
    67 	void SetAttributeL(TCookieAttributeName aAttributeName, THTTPHdrVal aAttributeVal);
       
    68 	
       
    69 	/** Attribute retrieves the value of an attribute
       
    70 		@param	aAttributeName	Identifies the attribute 
       
    71 		@param	aAttributeVal	The value being retrieved
       
    72 		@return	An error code. KErrNotFound will indicate that the cookie doesn't 
       
    73 		contain the specified attribute.
       
    74 	*/
       
    75 	TInt Attribute(TCookieAttributeName aAttributeName, THTTPHdrVal& aAttributeVal) const;
       
    76 
       
    77 	/** Did this cookie come from a SetCookie2 header?
       
    78 		@return	Flag indicating if this cookie was received in SetCookie2 header (rather 
       
    79 				than a SetCookie header).
       
    80 	*/
       
    81 	TBool FromCookie2() const;
       
    82 
       
    83 private:
       
    84 	/** Class to store the name and value of an individual cookie attribute
       
    85 	*/
       
    86 	class TCookieAttribute
       
    87 		{
       
    88 	public:
       
    89 	/** Constructor that initialises name and value of attribute
       
    90 		@param	aName	Identifies the attribute to be set
       
    91 		@param	aHdrVal	The value of the attribute
       
    92 	*/
       
    93 		TCookieAttribute(TCookieAttributeName aName, THTTPHdrVal aHdrVal);
       
    94 
       
    95 	/** Default constructor
       
    96 	*/
       
    97 		TCookieAttribute();
       
    98 	public:
       
    99 		/** The cookie attribute
       
   100 		*/
       
   101 		TCookieAttributeName iName;
       
   102 
       
   103 		/** The value of this attribute
       
   104 		*/
       
   105 		THTTPHdrVal iValue;
       
   106 		};
       
   107 
       
   108 	/** Constructor for CCookie
       
   109 		@param	aStringPool	String pool to be used by this cookie
       
   110 		@param	aCookie2	Flag indicating if this cookie was received in a SetCookie2 header
       
   111 	*/
       
   112 	CCookie(RStringPool aStringPool, TBool aCookie2);
       
   113 
       
   114 	/** Standard C class second phase construction method
       
   115 		@param aName		Name attribute for this cookie
       
   116 		@param aValue		Value attribute for this cookie
       
   117 	*/
       
   118 	void ConstructL(RString aName, RString aValue);
       
   119 
       
   120 	/** Closes a cookie attribute - used to ensure string attributes are
       
   121 		properly closed on destruction
       
   122 		@param aCookieAttribute	The attribute to be closed
       
   123 	*/
       
   124 	void CloseAttribute(TCookieAttribute aCookieAttribute);
       
   125 
       
   126 	/** Finds the specified attribute in this cookie
       
   127 		@param aAttribute		
       
   128 		@param aAttributeName	
       
   129 		@return The index in iAttributes of the specified attribute. KErrNotFound indicates 
       
   130 		that the cookie does not contain the attribute.
       
   131 	*/
       
   132 	TInt FindAttribute(TCookieAttributeName aAttributeName, TCookieAttribute& aAttribute) const;
       
   133 
       
   134 private:
       
   135 	/** String pool that can be used by this cookie
       
   136 	*/
       
   137 	RStringPool iStringPool;
       
   138 	
       
   139 	/** Array of the attributes of this cookie
       
   140 	*/
       
   141 	RArray<TCookieAttribute> iAttributes;
       
   142 
       
   143 	/** Flag indicating whether this cookie was received in a SetCookie2 header
       
   144 	*/
       
   145 	TBool iSetCookie2;
       
   146 	};
       
   147 
       
   148 #include "ccookie.inl"
       
   149 
       
   150 #endif //	__CCOOKIE_H__
       
   151