httpfilters/cookie/ManagerInc/CookieManagerServer.h
changeset 0 b16258d2340f
child 9 2611c08ee28e
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Declaration of class CCookieManagerServer
       
    15 *         
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef __COOKIEMANAGER_SERVER_H__
       
    21 #define __COOKIEMANAGER_SERVER_H__
       
    22 
       
    23 // INCLUDE FILES
       
    24 	// System includes
       
    25 #include <http.h>
       
    26 #include <f32file.h>
       
    27 #include <e32def.h>
       
    28 
       
    29 // Opcodes used in message passing between client and server
       
    30 enum TCookieServerRqst 
       
    31 	{
       
    32 	EStoreCookie,
       
    33   EClearAllCookies,
       
    34 	EGetCookieSize,
       
    35 	EGetCookies,
       
    36 	ESetAppUid
       
    37     };
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 
       
    41 class CCookie;
       
    42 class CCookieArray;
       
    43 class CCookieTimer;
       
    44 class CCookieManagerSession;
       
    45 class TCookiePacker;
       
    46 
       
    47 // CLASS DECLARATIONS
       
    48 
       
    49 /**
       
    50 *
       
    51 */
       
    52 NONSHARABLE_CLASS( CCookieManagerServer ) :
       
    53                              public CPolicyServer
       
    54 	{
       
    55 //    friend CCookieManagerSession;
       
    56 public:
       
    57     /**
       
    58     *
       
    59     */
       
    60     static CCookieManagerServer* NewL();
       
    61 
       
    62 protected:
       
    63 	CCookieManagerServer( TInt aPriority );
       
    64 
       
    65 public:
       
    66     /**
       
    67     * Standard destructor
       
    68     */
       
    69     ~CCookieManagerServer();
       
    70 
       
    71     /**
       
    72     *
       
    73     */
       
    74     void ConstructL();
       
    75 
       
    76     /**
       
    77     * Session notification on closing.
       
    78     * Care should be taken in clients NOT to call it if SERVER is closing...
       
    79     */
       
    80     void CloseSession();
       
    81 
       
    82     /**
       
    83     * Clears all cookies
       
    84     * @return The number of cookies removed
       
    85     */
       
    86     TInt ClearAllCookies();
       
    87 
       
    88     /**
       
    89     * Returns a pointer to the stringpool we currently use.
       
    90     */
       
    91     RStringPool* StringPool();
       
    92 
       
    93 
       
    94     /**
       
    95     * Returns a poitner for the persistent cookies we currently have.
       
    96     */
       
    97     CCookieArray* CookieArray();
       
    98 
       
    99 
       
   100     /**
       
   101     * Store a cookie in a persistent way. We take over the ownership
       
   102 	* of the cookie.
       
   103 	* If the cookie exists, that is, there is already a cookie whose NAME
       
   104 	* attribute is the same, then the new cookie supersedes the old when :
       
   105 	*	- the old and new Domain attribute value compare equal (case-
       
   106 	* insensitive),
       
   107 	*	- the old and new Path attribute values string-compare equal
       
   108 	* (case-sensitive).
       
   109 	* However, if the Max-Age attribute is zero, then the old and new cookies
       
   110 	* are discarded.
       
   111 	* @param aCookie The cookie to be stored.
       
   112 	* @param aRequestUri The current HTTP request-URI.
       
   113 	* @param aIndex Cookie is inserted at the position of existing cookie, and exisiting cookie is removed.
       
   114     */
       
   115     void StorePersistentCookieL( CCookie* aCookie, const TDesC8& aRequestUri, const TInt aIndex = -1 );
       
   116 
       
   117 	/**
       
   118 	*
       
   119 	*/
       
   120 	TInt GetCookies( const TDesC8& aRequestUri,
       
   121 					RPointerArray<CCookie>& aCookies ) const;
       
   122 	
       
   123 	/**
       
   124 	*Sets the File Name of the Cookie File using AppUid				
       
   125     *@param aFileName The AppUid of the Application
       
   126     */
       
   127     void SetFileName(TUint32& aAppUid);
       
   128     
       
   129     /**
       
   130     *@return the File Name of the Cookie file
       
   131     */    
       
   132     TDesC& GetFileName() const;
       
   133 
       
   134 private:
       
   135 	/**
       
   136 	* This method checks if there is enough space to persist the cookies.
       
   137 	* The requirement is to have at least KCookieMaxFileLength bytes on the
       
   138 	* specified (it is stored in the ini file) drive.
       
   139 	* @param aFileSystem File system reference, it is used for a system call,
       
   140 	* @param aFileName The name of the file into which we want to write
       
   141 	* cookies.
       
   142 	* @return ETrue if there is enough space for the file operation,
       
   143 	* EFalse otherwise.
       
   144 	*/
       
   145 	TBool CheckDiskSpace( RFs& aFileSystem, const TDesC& aFileName ) const;
       
   146 
       
   147     /**
       
   148     *
       
   149     */
       
   150     CSession2* DoNewSessionL();
       
   151 
       
   152 
       
   153 	/**
       
   154 	*
       
   155 	*/
       
   156 	virtual CSession2* NewSessionL( const TVersion& aVersion, 
       
   157                                     const RMessage2& aMessage ) const;
       
   158 
       
   159 
       
   160     /**
       
   161     * Reads the cookies from the file into a buffer. After reading the file
       
   162 	* content we can process it by calling ParseCookiesFromBufferL method.
       
   163 	* @return The error code indicating the type of failure.
       
   164     */
       
   165     TInt ReadCookiesFromFile();
       
   166 
       
   167 
       
   168     /**
       
   169     * Writes the currently valid cookies into a file.
       
   170 	* Note : it may happen that although this method returns an error code
       
   171 	* other than KErrNone, the cookies (not all, however) have been persisted.
       
   172 	* In this case, it indicates a failure during persisting a particular
       
   173 	* cookie, but it may not neccessarily be true for ALL cookies.
       
   174 	* @return The error code indicating the type of failure.
       
   175     */
       
   176     TInt WriteCookiesToFile();
       
   177 
       
   178 private:
       
   179     TUint32                 iSessionCount;
       
   180     TBool                   iServerClosing;
       
   181 
       
   182 	CCookieTimer*           iCloseTimer;
       
   183 
       
   184 	HBufC*                  iCookieFileName;
       
   185 
       
   186     RFs 					iFs;
       
   187     CCookieArray*			iPersistentCookies;	// new-style
       
   188 
       
   189     RStringPool             iStringPool;
       
   190 
       
   191 	// As we open our string pool only in ConstructL we cannot instantiate the
       
   192 	// cookie packer in the constructor :(
       
   193 	TCookiePacker*			iCookiePacker;
       
   194 
       
   195 	};
       
   196 
       
   197 
       
   198 //**********************************
       
   199 // CCookieTimer
       
   200 //**********************************
       
   201 //
       
   202 NONSHARABLE_CLASS( CCookieTimer ) : public CTimer
       
   203 	{
       
   204 	public :	// construction, destruction
       
   205 		/**
       
   206 		* Two-phase constructor
       
   207 		*/
       
   208 		static CCookieTimer* NewL();
       
   209 
       
   210 		/**
       
   211 		* Destructor
       
   212 		*/
       
   213 		~CCookieTimer();
       
   214 
       
   215 	protected :	// from CTimer
       
   216 		/**
       
   217 		* @see CActive::RunL
       
   218 		*/
       
   219 		void RunL();
       
   220 
       
   221 	private :	// construction
       
   222 		/**
       
   223 		* Constructor.
       
   224 		*/
       
   225 		CCookieTimer();
       
   226 	};
       
   227 
       
   228 #endif //__COOKIEMANAGER_SERVER_H__