applayerprotocols/httpexamples/cookies/cookiefilter/httpcookiefilter.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 __HTTPCOOKIEFILTER_H__
       
    17 #define __HTTPCOOKIEFILTER_H__
       
    18 
       
    19 #include <http/mhttpfilter.h>
       
    20 #include <http/rhttpsession.h>
       
    21 #include <http/ccookiefilterinterface.h>
       
    22 class MHttpCookieManager;
       
    23 class CCookie;
       
    24 
       
    25 /** CCookieFilter is used to trap outgoing requests, to add cookies to them, and incoming 
       
    26 	responses, to extract cookies from them.
       
    27 */
       
    28 class CCookieFilter : public CCookieFilterInterface, public MHTTPFilter
       
    29 	{
       
    30  public:
       
    31 	/** Installs the cookie filter, supplying it with this callback interface
       
    32 		@param aSession the session to install the filter into.
       
    33 		@leave KErrNoMemory There was not enough memory.
       
    34 	*/
       
    35 	static CCookieFilter* InstallFilterL(TAny* aFilterParams);
       
    36 
       
    37 	/** Standard destructor
       
    38 	*/
       
    39 	~CCookieFilter();
       
    40 
       
    41 	//From MHttpFilter
       
    42 	virtual void MHFRunL(RHTTPTransaction aTransaction,
       
    43 						 const THTTPEvent& aEvent);
       
    44 	virtual TInt MHFRunError(TInt aError, 
       
    45 							 RHTTPTransaction aTransaction,
       
    46 							 const THTTPEvent& aEvent);
       
    47 	virtual void MHFUnload(RHTTPSession aSession, 
       
    48 						   THTTPFilterHandle aHandle);
       
    49 	virtual void MHFLoad(RHTTPSession aSession, 
       
    50 						 THTTPFilterHandle aHandle);
       
    51 
       
    52 private:
       
    53 	/** Standard constructor
       
    54 	*/
       
    55 	CCookieFilter(RHTTPSession aSession, MHttpCookieManager& aCookieFilterCallback);
       
    56 
       
    57 	/** Standard C class second phase construction
       
    58 	*/
       
    59 	void ConstructL();
       
    60 
       
    61 	/** Check the response headers of the specified transaction and extract any cookies
       
    62 		from them for storage
       
    63 		@param	aTransaction	The transaction to handle the response headers
       
    64 	*/
       
    65 	void HandleResponseHeadersL(RHTTPTransaction aTransaction);
       
    66 
       
    67 	/** Find any cookies which are appropriate to this request and add them to the
       
    68 		outgoing request headers.
       
    69 		@param	aTransaction	The transaction to handle the request headers
       
    70 	*/
       
    71 	void HandleRequestHeadersL(RHTTPTransaction aTransaction);
       
    72 
       
    73 	/** Extracts a cookie from the headers and stores it
       
    74 		@param	aRequestHeaders	The headers which contain the cookie
       
    75 		@param	aPartIndex		The part index of the cookie within the headers
       
    76 		@param	aFieldName		The name of the header field we are storing.  Could be
       
    77 								SetCookie or SetCookie2
       
    78 		@param	aUri			The Uri that issued this cookie
       
    79 	*/
       
    80 	void StoreOneCookieL(RHTTPHeaders aRequestHeaders, TInt aPartIndex, RStringF aFieldName, const TUriC8& aUri);
       
    81 
       
    82 	/** Adds a specified cookie to an outgoing request
       
    83 		@param	aRequestHeaders	The request headers to which the cookie should be added
       
    84 		@param	aCookie			The cookie to add to the headers
       
    85 		@param	aPartIndex		The index of the cookie
       
    86 	*/
       
    87 	void AddCookieToRequestL(RHTTPHeaders aRequestHeaders, const CCookie& aCookie, TInt aPartIndex);
       
    88 
       
    89 private:
       
    90 	/** Count of how many times this filter has been loaded - used to ensure 
       
    91 		destruction happens at the correct time
       
    92 	*/
       
    93 	TInt iLoadCount;
       
    94 
       
    95 	/** String pool to be used by this cookie
       
    96 	*/
       
    97 	RStringPool iStringPool;
       
    98 
       
    99 	/** The current http session
       
   100 	*/
       
   101 	RHTTPSession iSession;
       
   102 
       
   103 	/** The manager which is used for storage and retrieval of cookies
       
   104 	*/
       
   105 	MHttpCookieManager& iCookieManager;
       
   106 
       
   107 	/** The string table which is used for storage of all strings
       
   108 	*/
       
   109 	const TStringTable& iStringTable;
       
   110 	};
       
   111 
       
   112 #endif //__HTTPCOOKIEFILTER_H__