LCOV - code coverage report
Current view: directory - netwerk/cookie - nsCookie.h (source / functions) Found Hit Coverage
Test: app.info Lines: 20 19 95.0 %
Date: 2012-06-02 Functions: 19 18 94.7 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Daniel Witte.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2003
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Daniel Witte (dwitte@stanford.edu)
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef nsCookie_h__
      40                 : #define nsCookie_h__
      41                 : 
      42                 : #include "nsICookie.h"
      43                 : #include "nsICookie2.h"
      44                 : #include "nsString.h"
      45                 : 
      46                 : /** 
      47                 :  * The nsCookie class is the main cookie storage medium for use within cookie
      48                 :  * code. It implements nsICookie2, which extends nsICookie, a frozen interface
      49                 :  * for xpcom access of cookie objects.
      50                 :  */
      51                 : 
      52                 : /******************************************************************************
      53                 :  * nsCookie:
      54                 :  * implementation
      55                 :  ******************************************************************************/
      56                 : 
      57                 : class nsCookie : public nsICookie2
      58                 : {
      59                 :   public:
      60                 :     // nsISupports
      61                 :     NS_DECL_ISUPPORTS
      62                 :     NS_DECL_NSICOOKIE
      63                 :     NS_DECL_NSICOOKIE2
      64                 : 
      65                 :   private:
      66                 :     // for internal use only. see nsCookie::Create().
      67           41965 :     nsCookie(const char     *aName,
      68                 :              const char     *aValue,
      69                 :              const char     *aHost,
      70                 :              const char     *aPath,
      71                 :              const char     *aEnd,
      72                 :              PRInt64         aExpiry,
      73                 :              PRInt64         aLastAccessed,
      74                 :              PRInt64         aCreationTime,
      75                 :              bool            aIsSession,
      76                 :              bool            aIsSecure,
      77                 :              bool            aIsHttpOnly)
      78                 :      : mName(aName)
      79                 :      , mValue(aValue)
      80                 :      , mHost(aHost)
      81                 :      , mPath(aPath)
      82                 :      , mEnd(aEnd)
      83                 :      , mExpiry(aExpiry)
      84                 :      , mLastAccessed(aLastAccessed)
      85                 :      , mCreationTime(aCreationTime)
      86                 :      , mIsSession(aIsSession != false)
      87                 :      , mIsSecure(aIsSecure != false)
      88           41965 :      , mIsHttpOnly(aIsHttpOnly != false)
      89                 :     {
      90           41965 :     }
      91                 : 
      92                 :   public:
      93                 :     // Generate a unique and monotonically increasing creation time. See comment
      94                 :     // in nsCookie.cpp.
      95                 :     static PRInt64 GenerateUniqueCreationTime(PRInt64 aCreationTime);
      96                 : 
      97                 :     // public helper to create an nsCookie object. use |operator delete|
      98                 :     // to destroy an object created by this method.
      99                 :     static nsCookie * Create(const nsACString &aName,
     100                 :                              const nsACString &aValue,
     101                 :                              const nsACString &aHost,
     102                 :                              const nsACString &aPath,
     103                 :                              PRInt64           aExpiry,
     104                 :                              PRInt64           aLastAccessed,
     105                 :                              PRInt64           aCreationTime,
     106                 :                              bool              aIsSession,
     107                 :                              bool              aIsSecure,
     108                 :                              bool              aIsHttpOnly);
     109                 : 
     110          167860 :     virtual ~nsCookie() {}
     111                 : 
     112                 :     // fast (inline, non-xpcom) getters
     113         4511649 :     inline const nsDependentCString Name()  const { return nsDependentCString(mName, mValue - 1); }
     114           15846 :     inline const nsDependentCString Value() const { return nsDependentCString(mValue, mHost - 1); }
     115         4516333 :     inline const nsDependentCString Host()  const { return nsDependentCString(mHost, mPath - 1); }
     116             530 :     inline const nsDependentCString RawHost() const { return nsDependentCString(IsDomain() ? mHost + 1 : mHost, mPath - 1); }
     117         4511473 :     inline const nsDependentCString Path()  const { return nsDependentCString(mPath, mEnd); }
     118           36154 :     inline PRInt64 Expiry()                 const { return mExpiry; }        // in seconds
     119           51650 :     inline PRInt64 LastAccessed()           const { return mLastAccessed; }  // in microseconds
     120           16643 :     inline PRInt64 CreationTime()           const { return mCreationTime; }  // in microseconds
     121           16583 :     inline bool IsSession()               const { return mIsSession; }
     122             534 :     inline bool IsDomain()                const { return *mHost == '.'; }
     123           15846 :     inline bool IsSecure()                const { return mIsSecure; }
     124           30901 :     inline bool IsHttpOnly()              const { return mIsHttpOnly; }
     125                 : 
     126                 :     // setters
     127           15214 :     inline void SetExpiry(PRInt64 aExpiry)        { mExpiry = aExpiry; }
     128               0 :     inline void SetLastAccessed(PRInt64 aTime)    { mLastAccessed = aTime; }
     129           15214 :     inline void SetIsSession(bool aIsSession)   { mIsSession = (bool) aIsSession; }
     130                 :     // Set the creation time manually, overriding the monotonicity checks in
     131                 :     // Create(). Use with caution!
     132              18 :     inline void SetCreationTime(PRInt64 aTime)    { mCreationTime = aTime; }
     133                 : 
     134                 :   protected:
     135                 :     // member variables
     136                 :     // we use char* ptrs to store the strings in a contiguous block,
     137                 :     // so we save on the overhead of using nsCStrings. However, we
     138                 :     // store a terminating null for each string, so we can hand them
     139                 :     // out as nsAFlatCStrings.
     140                 :     const char  *mName;
     141                 :     const char  *mValue;
     142                 :     const char  *mHost;
     143                 :     const char  *mPath;
     144                 :     const char  *mEnd;
     145                 :     PRInt64      mExpiry;
     146                 :     PRInt64      mLastAccessed;
     147                 :     PRInt64      mCreationTime;
     148                 :     bool mIsSession;
     149                 :     bool mIsSecure;
     150                 :     bool mIsHttpOnly;
     151                 : };
     152                 : 
     153                 : #endif // nsCookie_h__

Generated by: LCOV version 1.7