2003-10-11 03:09:18 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-19 02:01:16 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2003-10-11 03:09:18 +04:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2003-10-11 03:09:18 +04:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2003-10-11 03:09:18 +04:00
|
|
|
* Daniel Witte.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2003
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Daniel Witte (dwitte@stanford.edu)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-19 02:01:16 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2003-10-11 03:09:18 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-19 02:01:16 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2003-10-11 03:09:18 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef nsCookie_h__
|
|
|
|
#define nsCookie_h__
|
|
|
|
|
|
|
|
#include "nsICookie.h"
|
|
|
|
#include "nsICookie2.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The nsCookie class is the main cookie storage medium for use within cookie
|
|
|
|
* code. It implements nsICookie2, which extends nsICookie, a frozen interface
|
|
|
|
* for xpcom access of cookie objects.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* nsCookie:
|
|
|
|
* implementation
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class nsCookie : public nsICookie2
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// nsISupports
|
2007-10-04 23:24:00 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2003-10-11 03:09:18 +04:00
|
|
|
NS_DECL_NSICOOKIE
|
|
|
|
NS_DECL_NSICOOKIE2
|
|
|
|
|
2003-11-18 15:30:23 +03:00
|
|
|
private:
|
|
|
|
// for internal use only. see nsCookie::Create().
|
|
|
|
nsCookie(const char *aName,
|
|
|
|
const char *aValue,
|
|
|
|
const char *aHost,
|
|
|
|
const char *aPath,
|
|
|
|
const char *aEnd,
|
2007-06-18 01:52:22 +04:00
|
|
|
PRInt64 aExpiry,
|
2007-11-18 11:08:34 +03:00
|
|
|
PRInt64 aLastAccessed,
|
2010-10-20 04:24:52 +04:00
|
|
|
PRInt64 aCreationTime,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsSession,
|
|
|
|
bool aIsSecure,
|
|
|
|
bool aIsHttpOnly)
|
2009-12-20 02:55:56 +03:00
|
|
|
: mName(aName)
|
2003-11-18 15:30:23 +03:00
|
|
|
, mValue(aValue)
|
|
|
|
, mHost(aHost)
|
|
|
|
, mPath(aPath)
|
|
|
|
, mEnd(aEnd)
|
|
|
|
, mExpiry(aExpiry)
|
2007-11-18 11:08:34 +03:00
|
|
|
, mLastAccessed(aLastAccessed)
|
2010-10-20 04:24:52 +04:00
|
|
|
, mCreationTime(aCreationTime)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mIsSession(aIsSession != false)
|
|
|
|
, mIsSecure(aIsSecure != false)
|
|
|
|
, mIsHttpOnly(aIsHttpOnly != false)
|
2003-11-18 15:30:23 +03:00
|
|
|
{
|
|
|
|
}
|
2003-10-11 03:09:18 +04:00
|
|
|
|
2003-11-18 15:30:23 +03:00
|
|
|
public:
|
2010-10-20 04:24:52 +04:00
|
|
|
// Generate a unique and monotonically increasing creation time. See comment
|
|
|
|
// in nsCookie.cpp.
|
|
|
|
static PRInt64 GenerateUniqueCreationTime(PRInt64 aCreationTime);
|
2010-08-03 04:03:24 +04:00
|
|
|
|
2003-11-18 15:30:23 +03:00
|
|
|
// public helper to create an nsCookie object. use |operator delete|
|
|
|
|
// to destroy an object created by this method.
|
|
|
|
static nsCookie * Create(const nsACString &aName,
|
|
|
|
const nsACString &aValue,
|
|
|
|
const nsACString &aHost,
|
|
|
|
const nsACString &aPath,
|
2007-06-18 01:52:22 +04:00
|
|
|
PRInt64 aExpiry,
|
2007-11-18 11:08:34 +03:00
|
|
|
PRInt64 aLastAccessed,
|
2010-10-20 04:24:52 +04:00
|
|
|
PRInt64 aCreationTime,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsSession,
|
|
|
|
bool aIsSecure,
|
|
|
|
bool aIsHttpOnly);
|
2003-11-18 15:30:23 +03:00
|
|
|
|
2007-04-23 18:21:53 +04:00
|
|
|
virtual ~nsCookie() {}
|
2003-10-11 03:09:18 +04:00
|
|
|
|
|
|
|
// fast (inline, non-xpcom) getters
|
|
|
|
inline const nsDependentCString Name() const { return nsDependentCString(mName, mValue - 1); }
|
|
|
|
inline const nsDependentCString Value() const { return nsDependentCString(mValue, mHost - 1); }
|
|
|
|
inline const nsDependentCString Host() const { return nsDependentCString(mHost, mPath - 1); }
|
2003-10-22 10:53:19 +04:00
|
|
|
inline const nsDependentCString RawHost() const { return nsDependentCString(IsDomain() ? mHost + 1 : mHost, mPath - 1); }
|
2003-10-11 03:09:18 +04:00
|
|
|
inline const nsDependentCString Path() const { return nsDependentCString(mPath, mEnd); }
|
2007-11-18 11:08:34 +03:00
|
|
|
inline PRInt64 Expiry() const { return mExpiry; } // in seconds
|
|
|
|
inline PRInt64 LastAccessed() const { return mLastAccessed; } // in microseconds
|
2010-10-20 04:24:52 +04:00
|
|
|
inline PRInt64 CreationTime() const { return mCreationTime; } // in microseconds
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool IsSession() const { return mIsSession; }
|
|
|
|
inline bool IsDomain() const { return *mHost == '.'; }
|
|
|
|
inline bool IsSecure() const { return mIsSecure; }
|
|
|
|
inline bool IsHttpOnly() const { return mIsHttpOnly; }
|
2003-10-11 03:09:18 +04:00
|
|
|
|
2003-10-16 17:17:12 +04:00
|
|
|
// setters
|
2007-06-18 01:52:22 +04:00
|
|
|
inline void SetExpiry(PRInt64 aExpiry) { mExpiry = aExpiry; }
|
2007-11-18 11:08:34 +03:00
|
|
|
inline void SetLastAccessed(PRInt64 aTime) { mLastAccessed = aTime; }
|
2011-09-29 10:19:26 +04:00
|
|
|
inline void SetIsSession(bool aIsSession) { mIsSession = (bool) aIsSession; }
|
2010-10-20 04:24:52 +04:00
|
|
|
// Set the creation time manually, overriding the monotonicity checks in
|
|
|
|
// Create(). Use with caution!
|
|
|
|
inline void SetCreationTime(PRInt64 aTime) { mCreationTime = aTime; }
|
2003-10-11 03:09:18 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// member variables
|
|
|
|
// we use char* ptrs to store the strings in a contiguous block,
|
|
|
|
// so we save on the overhead of using nsCStrings. However, we
|
|
|
|
// store a terminating null for each string, so we can hand them
|
|
|
|
// out as nsAFlatCStrings.
|
2007-10-04 23:24:00 +04:00
|
|
|
const char *mName;
|
|
|
|
const char *mValue;
|
|
|
|
const char *mHost;
|
|
|
|
const char *mPath;
|
|
|
|
const char *mEnd;
|
|
|
|
PRInt64 mExpiry;
|
2007-11-18 11:08:34 +03:00
|
|
|
PRInt64 mLastAccessed;
|
2010-10-20 04:24:52 +04:00
|
|
|
PRInt64 mCreationTime;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsSession;
|
|
|
|
bool mIsSecure;
|
|
|
|
bool mIsHttpOnly;
|
2003-10-11 03:09:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsCookie_h__
|