Example #1
0
nsCookie *
nsCookie::Create(const nsACString &aName,
                 const nsACString &aValue,
                 const nsACString &aHost,
                 const nsACString &aPath,
                 int64_t           aExpiry,
                 int64_t           aLastAccessed,
                 int64_t           aCreationTime,
                 bool              aIsSession,
                 bool              aIsSecure,
                 bool              aIsHttpOnly,
                 const OriginAttributes& aOriginAttributes,
                 int32_t           aSameSite)
{
  // Ensure mValue contains a valid UTF-8 sequence. Otherwise XPConnect will
  // truncate the string after the first invalid octet.
  RefPtr<nsUTF8ConverterService> converter = new nsUTF8ConverterService();
  nsAutoCString aUTF8Value;
  converter->ConvertStringToUTF8(aValue, "UTF-8", false, true, 1, aUTF8Value);

  // find the required string buffer size, adding 4 for the terminating nulls
  const uint32_t stringLength = aName.Length() + aUTF8Value.Length() +
                                aHost.Length() + aPath.Length() + 4;

  // allocate contiguous space for the nsCookie and its strings -
  // we store the strings in-line with the nsCookie to save allocations
  void *place = ::operator new(sizeof(nsCookie) + stringLength);
  if (!place)
    return nullptr;

  // assign string members
  char *name, *value, *host, *path, *end;
  name = static_cast<char *>(place) + sizeof(nsCookie);
  StrBlockCopy(aName, aUTF8Value, aHost, aPath,
               name, value, host, path, end);

  // If the creationTime given to us is higher than the running maximum, update
  // our maximum.
  if (aCreationTime > gLastCreationTime)
    gLastCreationTime = aCreationTime;

  // If aSameSite is not a sensible value, assume strict
  if (aSameSite < 0 || aSameSite > nsICookie2::SAMESITE_STRICT) {
    aSameSite = nsICookie2::SAMESITE_STRICT;
  }

  // construct the cookie. placement new, oh yeah!
  return new (place) nsCookie(name, value, host, path, end,
                              aExpiry, aLastAccessed, aCreationTime,
                              aIsSession, aIsSecure, aIsHttpOnly,
                              aOriginAttributes, aSameSite);
}
Example #2
0
nsCookie *
nsCookie::Create(const nsACString &aName,
                 const nsACString &aValue,
                 const nsACString &aHost,
                 const nsACString &aPath,
                 PRInt64           aExpiry,
                 PRInt64           aLastAccessed,
                 PRInt64           aCreationID,
                 PRBool            aIsSession,
                 PRBool            aIsSecure,
                 PRBool            aIsHttpOnly)
{
  // find the required string buffer size, adding 4 for the terminating nulls
  const PRUint32 stringLength = aName.Length() + aValue.Length() +
                                aHost.Length() + aPath.Length() + 4;

  // allocate contiguous space for the nsCookie and its strings -
  // we store the strings in-line with the nsCookie to save allocations
  void *place = ::operator new(sizeof(nsCookie) + stringLength);
  if (!place)
    return nsnull;

  // assign string members
  char *name, *value, *host, *path, *end;
  name = static_cast<char *>(place) + sizeof(nsCookie);
  StrBlockCopy(aName, aValue, aHost, aPath,
               name, value, host, path, end);

  // check if the creation id given to us is greater than the running maximum
  // (it should always be monotonically increasing). if it's not, make up our own.
  if (aCreationID > gLastCreationID)
    gLastCreationID = aCreationID;
  else
    aCreationID = ++gLastCreationID;

  // construct the cookie. placement new, oh yeah!
  return new (place) nsCookie(name, value, host, path, end,
                              aExpiry, aLastAccessed, aCreationID,
                              aIsSession, aIsSecure, aIsHttpOnly);
}
Example #3
0
nsCookie *
nsCookie::Create(const nsACString &aName,
                 const nsACString &aValue,
                 const nsACString &aHost,
                 const nsACString &aPath,
                 PRInt64           aExpiry,
                 PRInt64           aLastAccessed,
                 PRInt64           aCreationTime,
                 bool              aIsSession,
                 bool              aIsSecure,
                 bool              aIsHttpOnly)
{
  // find the required string buffer size, adding 4 for the terminating nulls
  const PRUint32 stringLength = aName.Length() + aValue.Length() +
                                aHost.Length() + aPath.Length() + 4;

  // allocate contiguous space for the nsCookie and its strings -
  // we store the strings in-line with the nsCookie to save allocations
  void *place = ::operator new(sizeof(nsCookie) + stringLength);
  if (!place)
    return nsnull;

  // assign string members
  char *name, *value, *host, *path, *end;
  name = static_cast<char *>(place) + sizeof(nsCookie);
  StrBlockCopy(aName, aValue, aHost, aPath,
               name, value, host, path, end);

  // If the creationTime given to us is higher than the running maximum, update
  // our maximum.
  if (aCreationTime > gLastCreationTime)
    gLastCreationTime = aCreationTime;

  // construct the cookie. placement new, oh yeah!
  return new (place) nsCookie(name, value, host, path, end,
                              aExpiry, aLastAccessed, aCreationTime,
                              aIsSession, aIsSecure, aIsHttpOnly);
}