netwerk/cookie/nsCookie.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
parent 0
6474c204b198
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nsCookie_h__
     7 #define nsCookie_h__
     9 #include "nsICookie.h"
    10 #include "nsICookie2.h"
    11 #include "nsString.h"
    13 #include "mozilla/MemoryReporting.h"
    15 /** 
    16  * The nsCookie class is the main cookie storage medium for use within cookie
    17  * code. It implements nsICookie2, which extends nsICookie, a frozen interface
    18  * for xpcom access of cookie objects.
    19  */
    21 /******************************************************************************
    22  * nsCookie:
    23  * implementation
    24  ******************************************************************************/
    26 class nsCookie : public nsICookie2
    27 {
    28   public:
    29     // nsISupports
    30     NS_DECL_ISUPPORTS
    31     NS_DECL_NSICOOKIE
    32     NS_DECL_NSICOOKIE2
    34   private:
    35     // for internal use only. see nsCookie::Create().
    36     nsCookie(const char     *aName,
    37              const char     *aValue,
    38              const char     *aHost,
    39              const char     *aOrigin,
    40              const char     *aPath,
    41              const char     *aEnd,
    42              int64_t         aExpiry,
    43              int64_t         aLastAccessed,
    44              int64_t         aCreationTime,
    45              bool            aIsSession,
    46              bool            aIsSecure,
    47              bool            aIsHttpOnly)
    48      : mName(aName)
    49      , mValue(aValue)
    50      , mHost(aHost)
    51      , mOrigin(aOrigin)
    52      , mPath(aPath)
    53      , mEnd(aEnd)
    54      , mExpiry(aExpiry)
    55      , mLastAccessed(aLastAccessed)
    56      , mCreationTime(aCreationTime)
    57      , mIsSession(aIsSession != false)
    58      , mIsSecure(aIsSecure != false)
    59      , mIsHttpOnly(aIsHttpOnly != false)
    60     {
    61     }
    63   public:
    64     // Generate a unique and monotonically increasing creation time. See comment
    65     // in nsCookie.cpp.
    66     static int64_t GenerateUniqueCreationTime(int64_t aCreationTime);
    68     // public helper to create an nsCookie object. use |operator delete|
    69     // to destroy an object created by this method.
    70     static nsCookie * Create(const nsACString &aName,
    71                              const nsACString &aValue,
    72                              const nsACString &aHost,
    73                              const nsACString &aOrigin,
    74                              const nsACString &aPath,
    75                              int64_t           aExpiry,
    76                              int64_t           aLastAccessed,
    77                              int64_t           aCreationTime,
    78                              bool              aIsSession,
    79                              bool              aIsSecure,
    80                              bool              aIsHttpOnly);
    82     virtual ~nsCookie() {}
    84     size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
    86     // fast (inline, non-xpcom) getters
    87     inline const nsDependentCString Name()  const { return nsDependentCString(mName, mValue - 1); }
    88     inline const nsDependentCString Value() const { return nsDependentCString(mValue, mHost - 1); }
    89     inline const nsDependentCString Host()  const { return nsDependentCString(mHost, mOrigin - 1); }
    90     inline const nsDependentCString RawHost() const { return nsDependentCString(IsDomain() ? mHost + 1 : mHost, mOrigin - 1); }
    91     inline const nsDependentCString Origin() const { return nsDependentCString(mOrigin, mPath - 1); }
    92     inline const nsDependentCString Path()  const { return nsDependentCString(mPath, mEnd); }
    93     inline int64_t Expiry()                 const { return mExpiry; }        // in seconds
    94     inline int64_t LastAccessed()           const { return mLastAccessed; }  // in microseconds
    95     inline int64_t CreationTime()           const { return mCreationTime; }  // in microseconds
    96     inline bool IsSession()               const { return mIsSession; }
    97     inline bool IsDomain()                const { return *mHost == '.'; }
    98     inline bool IsSecure()                const { return mIsSecure; }
    99     inline bool IsHttpOnly()              const { return mIsHttpOnly; }
   101     // setters
   102     inline void SetExpiry(int64_t aExpiry)        { mExpiry = aExpiry; }
   103     inline void SetLastAccessed(int64_t aTime)    { mLastAccessed = aTime; }
   104     inline void SetIsSession(bool aIsSession)   { mIsSession = (bool) aIsSession; }
   105     // Set the creation time manually, overriding the monotonicity checks in
   106     // Create(). Use with caution!
   107     inline void SetCreationTime(int64_t aTime)    { mCreationTime = aTime; }
   109   protected:
   110     // member variables
   111     // we use char* ptrs to store the strings in a contiguous block,
   112     // so we save on the overhead of using nsCStrings. However, we
   113     // store a terminating null for each string, so we can hand them
   114     // out as nsAFlatCStrings.
   115     //
   116     // Please update SizeOfIncludingThis if this strategy changes.
   117     const char  *mName;
   118     const char  *mValue;
   119     const char  *mHost;
   120     const char  *mOrigin;
   121     const char  *mPath;
   122     const char  *mEnd;
   123     int64_t      mExpiry;
   124     int64_t      mLastAccessed;
   125     int64_t      mCreationTime;
   126     bool mIsSession;
   127     bool mIsSecure;
   128     bool mIsHttpOnly;
   129 };
   131 #endif // nsCookie_h__

mercurial