Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsCookieService.cpp File Reference
#include "nsCookieService.h"
#include "nsIServiceManager.h"
#include "nsIIOService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
#include "nsIPrefService.h"
#include "nsICookieConsent.h"
#include "nsICookiePermission.h"
#include "nsIURI.h"
#include "nsIURL.h"
#include "nsIChannel.h"
#include "nsIHttpChannel.h"
#include "nsIHttpChannelInternal.h"
#include "nsIPrompt.h"
#include "nsITimer.h"
#include "nsIFile.h"
#include "nsIObserverService.h"
#include "nsILineInputStream.h"
#include "nsCOMArray.h"
#include "nsArrayEnumerator.h"
#include "nsAutoPtr.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "prtime.h"
#include "prprf.h"
#include "prnetdb.h"
#include "nsNetUtil.h"
#include "nsNetCID.h"
#include "nsAppDirectoryServiceDefs.h"

Go to the source code of this file.

Classes

struct  nsListIter
struct  nsEnumerationData

Defines

#define LIMIT(x, low, high, default)   ((x) >= (low) && (x) <= (high) ? (x) : (default))
#define USEC_PER_SEC   (nsInt64(1000000))
#define NOW_IN_SECONDS   (nsInt64(PR_Now()) / USEC_PER_SEC)
#define SET_COOKIE   PR_TRUE
#define GET_COOKIE   PR_FALSE
#define COOKIE_LOGFAILURE(a, b, c, d)   /* nothing */
#define COOKIE_LOGSUCCESS(a, b, c, d)   /* nothing */

Functions

 compareCookiesForSending (const void *aElement1, const void *aElement2, void *aData)
 compareCookiesForWriting (const void *aElement1, const void *aElement2, void *aData)
 NS_IMPL_ISUPPORTS5 (nsCookieService, nsICookieService, nsICookieManager, nsICookieManager2, nsIObserver, nsISupportsWeakReference) nsCookieService
static PRBool ispathdelimiter (char c)
 COMArrayCallback (nsCookieEntry *aEntry, void *aArg)
 cookieListCallback (nsCookieEntry *aEntry, void *aArg)
static PRBool iswhitespace (char c)
static PRBool isterminator (char c)
static PRBool isquoteterminator (char c)
static PRBool isvalueseparator (char c)
static PRBool istokenseparator (char c)
PLDHashOperator PR_CALLBACK removeExpiredCallback (nsCookieEntry *aEntry, void *aArg)
 findOldestCallback (nsCookieEntry *aEntry, void *aArg)

Variables

static const char kHttpOnlyPrefix [] = "#HttpOnly_"
static const char kCookieFileName [] = "cookies.txt"
static const PRUint32 kLazyWriteTimeout = 5000
static const PRUint32 kMaxNumberOfCookies = 1000
static const PRUint32 kMaxCookiesPerHost = 50
static const PRUint32 kMaxBytesPerCookie = 4096
static const PRUint32 kMaxBytesPerPath = 1024
static const nsCookieStatus STATUS_REJECTED_WITH_ERROR = 5
static const PRUint32 BEHAVIOR_ACCEPT = 0
static const PRUint32 BEHAVIOR_REJECTFOREIGN = 1
static const PRUint32 BEHAVIOR_REJECT = 2
static const PRUint32 BEHAVIOR_P3P = 3
static const char kPrefCookiesPermissions [] = "network.cookie.cookieBehavior"
static const char kPrefMaxNumberOfCookies [] = "network.cookie.maxNumber"
static const char kPrefMaxCookiesPerHost [] = "network.cookie.maxPerHost"

Class Documentation

struct nsCookieAttributes

Definition at line 122 of file nsCookieService.cpp.

Collaboration diagram for nsCookieAttributes:
Class Members
nsCAutoString expires
nsInt64 expiryTime
nsCAutoString host
PRBool isHttpOnly
PRBool isSecure
PRBool isSession
nsCAutoString maxage
nsCAutoString name
nsCAutoString path
nsCAutoString value

Define Documentation

#define COOKIE_LOGFAILURE (   a,
  b,
  c,
  d 
)    /* nothing */

Definition at line 295 of file nsCookieService.cpp.

#define COOKIE_LOGSUCCESS (   a,
  b,
  c,
  d 
)    /* nothing */

Definition at line 296 of file nsCookieService.cpp.

Definition at line 202 of file nsCookieService.cpp.

#define LIMIT (   x,
  low,
  high,
  default 
)    ((x) >= (low) && (x) <= (high) ? (x) : (default))

Definition at line 89 of file nsCookieService.cpp.

Definition at line 108 of file nsCookieService.cpp.

Definition at line 201 of file nsCookieService.cpp.

#define USEC_PER_SEC   (nsInt64(1000000))

Definition at line 107 of file nsCookieService.cpp.


Function Documentation

COMArrayCallback ( nsCookieEntry aEntry,
void aArg 
)

Definition at line 852 of file nsCookieService.cpp.

{
  for (nsCookie *cookie = aEntry->Head(); cookie; cookie = cookie->Next()) {
    NS_STATIC_CAST(nsCOMArray<nsICookie>*, aArg)->AppendObject(cookie);
  }
  return PL_DHASH_NEXT;
}
compareCookiesForSending ( const void aElement1,
const void aElement2,
void aData 
)

Definition at line 311 of file nsCookieService.cpp.

{
  const nsCookie *cookie1 = NS_STATIC_CAST(const nsCookie*, aElement1);
  const nsCookie *cookie2 = NS_STATIC_CAST(const nsCookie*, aElement2);

  // compare by cookie path length in accordance with RFC2109
  int rv = cookie2->Path().Length() - cookie1->Path().Length();
  if (rv == 0) {
    // when path lengths match, older cookies should be listed first.  this is
    // required for backwards compatibility since some websites erroneously
    // depend on receiving cookies in the order in which they were sent to the
    // browser!  see bug 236772.
    rv = cookie1->CreationTime() - cookie2->CreationTime();
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

compareCookiesForWriting ( const void aElement1,
const void aElement2,
void aData 
)

Definition at line 333 of file nsCookieService.cpp.

{
  const nsCookie *cookie1 = NS_STATIC_CAST(const nsCookie*, aElement1);
  const nsCookie *cookie2 = NS_STATIC_CAST(const nsCookie*, aElement2);

  // we may have overflow problems returning the result directly, so we need branches
  nsInt64 difference = cookie2->LastAccessed() - cookie1->LastAccessed();
  return (difference > nsInt64(0)) ? 1 : (difference < nsInt64(0)) ? -1 : 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

cookieListCallback ( nsCookieEntry aEntry,
void aArg 
)

Definition at line 1068 of file nsCookieService.cpp.

{
  for (nsCookie *cookie = aEntry->Head(); cookie; cookie = cookie->Next()) {
    NS_STATIC_CAST(nsVoidArray*, aArg)->AppendElement(cookie);
  }
  return PL_DHASH_NEXT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

findOldestCallback ( nsCookieEntry aEntry,
void aArg 
)

Definition at line 2191 of file nsCookieService.cpp.

{
  nsEnumerationData *data = NS_STATIC_CAST(nsEnumerationData*, aArg);
  for (nsListIter iter(aEntry, nsnull, aEntry->Head()); iter.current; ++iter) {
    // check if we've found the oldest cookie so far
    if (data->oldestTime > iter.current->LastAccessed()) {
      data->oldestTime = iter.current->LastAccessed();
      data->iter = iter;
    }
  }
  return PL_DHASH_NEXT;
}

Here is the caller graph for this function:

static PRBool ispathdelimiter ( char  c) [inline, static]

Definition at line 493 of file nsCookieService.cpp.

{ return c == '/' || c == '?' || c == '#' || c == ';'; }

Here is the caller graph for this function:

static PRBool isquoteterminator ( char  c) [inline, static]

Definition at line 1466 of file nsCookieService.cpp.

{ return isterminator(c) || c == '"'; }

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool isterminator ( char  c) [inline, static]

Definition at line 1465 of file nsCookieService.cpp.

{ return c == '\n' || c == '\r'; }

Here is the caller graph for this function:

static PRBool istokenseparator ( char  c) [inline, static]

Definition at line 1468 of file nsCookieService.cpp.

{ return isvalueseparator(c) || c == '='; }

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool isvalueseparator ( char  c) [inline, static]

Definition at line 1467 of file nsCookieService.cpp.

{ return isterminator(c) || c == ';'; }

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool iswhitespace ( char  c) [inline, static]

Definition at line 1464 of file nsCookieService.cpp.

{ return c == ' '  || c == '\t'; }

Here is the caller graph for this function:

Definition at line 382 of file nsCookieService.cpp.

 : mCookieCount(0)
 , mCookieChanged(PR_FALSE)
 , mCookieIconVisible(PR_FALSE)
 , mCookiesPermissions(BEHAVIOR_ACCEPT)
 , mMaxNumberOfCookies(kMaxNumberOfCookies)
 , mMaxCookiesPerHost(kMaxCookiesPerHost)
{
}

Definition at line 2048 of file nsCookieService.cpp.

{
  const nsInt64 &currentTime = *NS_STATIC_CAST(nsInt64*, aArg);
  for (nsListIter iter(aEntry, nsnull, aEntry->Head()); iter.current; ) {
    if (iter.current->Expiry() <= currentTime)
      // remove from list. this takes care of updating the iterator for us
      nsCookieService::gCookieService->RemoveCookieFromList(iter);
    else
      ++iter;
  }
  return PL_DHASH_NEXT;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 111 of file nsCookieService.cpp.

const PRUint32 BEHAVIOR_P3P = 3 [static]

Definition at line 114 of file nsCookieService.cpp.

Definition at line 113 of file nsCookieService.cpp.

Definition at line 112 of file nsCookieService.cpp.

const char kCookieFileName[] = "cookies.txt" [static]

Definition at line 84 of file nsCookieService.cpp.

const char kHttpOnlyPrefix[] = "#HttpOnly_" [static]

Definition at line 82 of file nsCookieService.cpp.

const PRUint32 kLazyWriteTimeout = 5000 [static]

Definition at line 86 of file nsCookieService.cpp.

Definition at line 95 of file nsCookieService.cpp.

const PRUint32 kMaxBytesPerPath = 1024 [static]

Definition at line 96 of file nsCookieService.cpp.

Definition at line 94 of file nsCookieService.cpp.

Definition at line 93 of file nsCookieService.cpp.

const char kPrefCookiesPermissions[] = "network.cookie.cookieBehavior" [static]

Definition at line 117 of file nsCookieService.cpp.

const char kPrefMaxCookiesPerHost[] = "network.cookie.maxPerHost" [static]

Definition at line 119 of file nsCookieService.cpp.

const char kPrefMaxNumberOfCookies[] = "network.cookie.maxNumber" [static]

Definition at line 118 of file nsCookieService.cpp.

Definition at line 103 of file nsCookieService.cpp.