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.

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

mercurial