webengine/osswebengine/WebCore/platform/network/symbian/CookieHandler.h
changeset 0 dd21522fd290
child 70 8bfb9186a8b8
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 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 the License "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:  class definition for accessing cookies from script
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef COOKIE_HANDLER_H
       
    20 #define COOKIE_HANDLER_H
       
    21 
       
    22 // System includes
       
    23 #include <e32base.h>
       
    24 
       
    25 // CONSTANTS
       
    26 
       
    27 const TUint8 KMaxNumOfTypes = 30;
       
    28 
       
    29 // MACROS
       
    30 
       
    31 // DATA TYPES
       
    32 
       
    33 // FUNCTION PROTOTYPES
       
    34 
       
    35 // FORWARD DECLARATIONS
       
    36 class RStringPool;
       
    37 class CCookie;
       
    38 class RStringF;
       
    39 class RCookieManager;
       
    40 // CLASS DECLARATION
       
    41 
       
    42 struct CookieRecord
       
    43     {
       
    44     CookieRecord():
       
    45                   m_name(KNullDesC),m_nameValue(KNullDesC),m_expires(KNullDesC),
       
    46                   m_pathName(KNullDesC),m_domainName(KNullDesC),m_secure(KNullDesC) {}
       
    47     TPtrC m_name;
       
    48     TPtrC m_nameValue;
       
    49     TPtrC m_expires;
       
    50     TPtrC m_pathName;
       
    51     TPtrC m_domainName;
       
    52     TPtrC m_secure;
       
    53     };
       
    54 /**
       
    55 * This class encapsulates a cookie handler functions to be accessed from
       
    56 * ecma script, The following cookie fields are supported.
       
    57 *  "cookieName=cookieData;
       
    58 *  [;expires=timeInGmtString]
       
    59 *  [;path=pathName]
       
    60 *  [;domain=domainName]
       
    61 *  [;secure]"
       
    62 */
       
    63 class CookieHandler
       
    64     {
       
    65     public :    // construction, destruction
       
    66         /**
       
    67         * Creates a new object.
       
    68         * @return The constructed session.
       
    69         */
       
    70         static CookieHandler* init();
       
    71 
       
    72         /**
       
    73         * adds cookie ,
       
    74         * @param aUrl ,document.url
       
    75         * @param aCookieData,cookie buffer
       
    76         */
       
    77         void addCookie(const TDesC& aCookieData, const TDesC8& aUrl, const TDesC8& aPolicyBaseURL);
       
    78 
       
    79         /**
       
    80         * retrives all the cookies name and value pairs delimited by ';' and ' '
       
    81         * @param aUrl ,document.url
       
    82         * @return TText* cookies flattened on to the buffer.
       
    83         */
       
    84         TText* cookiesForUrl(const TDesC8& aUrl, TInt32& aLen);
       
    85 
       
    86         /**
       
    87         * Destructor.
       
    88         */
       
    89         virtual ~CookieHandler();
       
    90 
       
    91     private :    // constructors
       
    92         /**
       
    93         * Constructor.
       
    94         */
       
    95         CookieHandler( );
       
    96 
       
    97         /**
       
    98         * ConstructL.
       
    99         * @return None.
       
   100         */
       
   101         void constructL( );
       
   102 
       
   103         void addCookieL(const TDesC& aCookieData, const TDesC8& aUrl, const TDesC8& aPolicyBaseURL);
       
   104         TText* cookiesForUrlL(const TDesC8& aUrl, TInt32& aLen);
       
   105 
       
   106         /**
       
   107         * Auxillary function to convert 16 bit data to 8 bit.
       
   108         * @return HBufC8 - 8 bit data.
       
   109         */
       
   110         HBufC8* unicodeToAsciiLC( const TDesC16& aString ) const;
       
   111 
       
   112         /**
       
   113         * Auxillary function to convert 8 bit data to 16 bit.
       
   114         * @return HBufC16 - 16 bit data.
       
   115         */
       
   116         HBufC16* asciiToUnicodeLC( const TDesC8& aString ) const;
       
   117 
       
   118         /**
       
   119         * @param   the strings that are to be stored in stringpool
       
   120                                             RStringF& aName,
       
   121                                             RStringF& aNameValue,
       
   122                                             RStringF& aExpires,
       
   123                                             RStringF& aPath,
       
   124                                             RStringF& aDomain,
       
   125                                             RStringF& aVersion
       
   126 
       
   127           @param const CookieRecord& aCookieRecord  , parsed cookie fields
       
   128 
       
   129         * Initializes the string with values from CookieRecord structure.
       
   130         */
       
   131         void initAttributesForLongCookieLC( RStringF& aName,
       
   132                                             RStringF& aNameValue,
       
   133                                             RStringF& aExpires,
       
   134                                             RStringF& aPath,
       
   135                                             RStringF& aDomain,
       
   136                                             RStringF& aVersion,
       
   137                                             const CookieRecord& aCookieRecord) const;
       
   138         /**
       
   139         * Auxillary function to convert the cookie class to string . If the buffer is NULL
       
   140         * then the value is not copied
       
   141         * @param aCookieBuffer cookie buffer.to append the cooke  field strings
       
   142         * @param aCookiesSize total size of the cookie string
       
   143         */
       
   144         void cookiesToStringL(HBufC8* aCookieBuffer, TInt& aCookiesSize);
       
   145 
       
   146         /**
       
   147         * Auxillary function to parse the cookie buffer and to extract the fields .
       
   148         * @param aCookieField cookie field to be retrived .
       
   149         * @param aCookieString cookie buffer.
       
   150         * @param aEndIndex cosumed bytes from the buffer.
       
   151         * @return TPtrC - descriptor to the field value.
       
   152         */
       
   153         TPtrC getCookieFieldValue(const TDesC& aCookieField,
       
   154                                   const TPtrC& aCookieString ,
       
   155                                   TInt& aEndIndex) const ;
       
   156 
       
   157         /**
       
   158         * Auxillary function to parse and assigns the cookie field structure.
       
   159         * @param aCookieString cookie buffer.
       
   160         * @param aCookieRecord cookie fields structure.
       
   161         */
       
   162         void parseCookieFieldsL( const TPtrC& aCookieString,
       
   163                                  CookieRecord& aCookieRecord) const;
       
   164     private :    // data members
       
   165         RStringPool* m_stringPool ;// <<has
       
   166         RPointerArray<CCookie> m_getCookies;// <<has
       
   167         RCookieManager* m_cookieManager; // NOTE: should not use pointers to r-class, but RCookieManager
       
   168                     // class doesn't provide a default constructor, too bad :(
       
   169     };
       
   170 
       
   171 #endif