Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QNetworkCookiePrivate Class Reference

#include <qnetworkcookie_p.h>

Inheritance diagram for QNetworkCookiePrivate:
QSharedData

Public Functions

 QNetworkCookiePrivate ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 

Static Public Functions

static QList< QNetworkCookieparseSetCookieHeaderLine (const QByteArray &cookieString)
 

Public Variables

QString comment
 
QString domain
 
QDateTime expirationDate
 
bool httpOnly
 
QByteArray name
 
QString path
 
bool secure
 
QByteArray value
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Definition at line 60 of file qnetworkcookie_p.h.

Constructors and Destructors

◆ QNetworkCookiePrivate()

QNetworkCookiePrivate::QNetworkCookiePrivate ( )
inline

Definition at line 63 of file qnetworkcookie_p.h.

Functions

◆ parseSetCookieHeaderLine()

QList< QNetworkCookie > QNetworkCookiePrivate::parseSetCookieHeaderLine ( const QByteArray cookieString)
static

Definition at line 955 of file qnetworkcookie.cpp.

Referenced by QNetworkCookie::parseCookies(), and QNetworkCookiePrivate().

956 {
957  // According to http://wp.netscape.com/newsref/std/cookie_spec.html,<
958  // the Set-Cookie response header is of the format:
959  //
960  // Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure
961  //
962  // where only the NAME=VALUE part is mandatory
963  //
964  // We do not support RFC 2965 Set-Cookie2-style cookies
965 
966  QList<QNetworkCookie> result;
968 
969  int position = 0;
970  const int length = cookieString.length();
971  while (position < length) {
972  QNetworkCookie cookie;
973 
974  // The first part is always the "NAME=VALUE" part
975  QPair<QByteArray,QByteArray> field = nextField(cookieString, position, true);
976  if (field.first.isEmpty() || field.second.isNull())
977  // parsing error
978  break;
979  cookie.setName(field.first);
980  cookie.setValue(field.second);
981 
982  position = nextNonWhitespace(cookieString, position);
983  while (position < length) {
984  switch (cookieString.at(position++)) {
985  case ';':
986  // new field in the cookie
987  field = nextField(cookieString, position, false);
988  field.first = field.first.toLower(); // everything but the NAME=VALUE is case-insensitive
989 
990  if (field.first == "expires") {
991  position -= field.second.length();
992  int end;
993  for (end = position; end < length; ++end)
994  if (isValueSeparator(cookieString.at(end)))
995  break;
996 
997  QByteArray dateString = cookieString.mid(position, end - position).trimmed();
998  position = end;
999  QDateTime dt = parseDateString(dateString.toLower());
1000  if (!dt.isValid()) {
1001  return result;
1002  }
1003  cookie.setExpirationDate(dt);
1004  } else if (field.first == "domain") {
1005  QByteArray rawDomain = field.second;
1006  QString maybeLeadingDot;
1007  if (rawDomain.startsWith('.')) {
1008  maybeLeadingDot = QLatin1Char('.');
1009  rawDomain = rawDomain.mid(1);
1010  }
1011 
1012  QString normalizedDomain = QUrl::fromAce(QUrl::toAce(QString::fromUtf8(rawDomain)));
1013  if (normalizedDomain.isEmpty() && !rawDomain.isEmpty())
1014  return result;
1015  cookie.setDomain(maybeLeadingDot + normalizedDomain);
1016  } else if (field.first == "max-age") {
1017  bool ok = false;
1018  int secs = field.second.toInt(&ok);
1019  if (!ok)
1020  return result;
1021  cookie.setExpirationDate(now.addSecs(secs));
1022  } else if (field.first == "path") {
1024  cookie.setPath(path);
1025  } else if (field.first == "secure") {
1026  cookie.setSecure(true);
1027  } else if (field.first == "httponly") {
1028  cookie.setHttpOnly(true);
1029  } else if (field.first == "comment") {
1030  //cookie.setComment(QString::fromUtf8(field.second));
1031  } else if (field.first == "version") {
1032  if (field.second != "1") {
1033  // oops, we don't know how to handle this cookie
1034  return result;
1035  }
1036  } else {
1037  // got an unknown field in the cookie
1038  // what do we do?
1039  }
1040 
1041  position = nextNonWhitespace(cookieString, position);
1042  }
1043  }
1044 
1045  if (!cookie.name().isEmpty())
1046  result += cookie;
1047  }
1048 
1049  return result;
1050 }
QDateTime addSecs(int secs) const
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or...
Definition: qdatetime.cpp:2869
static QString fromPercentEncoding(const QByteArray &)
Returns a decoded copy of input.
Definition: qurl.cpp:5992
void setExpirationDate(const QDateTime &date)
Sets the expiration date of this cookie to date.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void setHttpOnly(bool enable)
Sets this cookie&#39;s "HttpOnly" flag to enable.
T1 first
Definition: qpair.h:65
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
T2 second
Definition: qpair.h:66
QByteArray toLower() const
Returns a lowercase copy of the byte array.
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
void setDomain(const QString &domain)
Sets the domain associated with this cookie to be domain.
void setPath(const QString &path)
Sets the path associated with this cookie to be path.
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
static int nextNonWhitespace(const QByteArray &text, int from)
static QByteArray toAce(const QString &)
Returns the ASCII Compatible Encoding of the given domain name domain.
Definition: qurl.cpp:6158
static bool isValueSeparator(char c)
void setName(const QByteArray &cookieName)
Sets the name of this cookie to be cookieName.
static QDateTime parseDateString(const QByteArray &dateString)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setSecure(bool enable)
Sets the secure flag of this cookie to enable.
QByteArray trimmed() const
Returns a byte array that has whitespace removed from the start and the end.
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
bool isNull() const
Returns true if this byte array is null; otherwise returns false.
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
static QString fromAce(const QByteArray &)
Returns the Unicode form of the given domain name domain, which is encoded in the ASCII Compatible En...
Definition: qurl.cpp:6134
QDateTime toUTC() const
Returns a datetime containing the date and time information in this datetime, but specified using the...
Definition: qdatetime.h:251
int length() const
Same as size().
Definition: qbytearray.h:356
The QNetworkCookie class holds one network cookie.
static QPair< QByteArray, QByteArray > nextField(const QByteArray &text, int &position, bool isNameValue)
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
QByteArray name() const
Returns the name of this cookie.
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
Definition: qdatetime.cpp:3138
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
static const KeyPair *const end
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void setValue(const QByteArray &value)
Sets the value of this cookie to be value.

Properties

◆ comment

QString QNetworkCookiePrivate::comment

Definition at line 69 of file qnetworkcookie_p.h.

Referenced by QNetworkCookie::operator==().

◆ domain

QString QNetworkCookiePrivate::domain

◆ expirationDate

QDateTime QNetworkCookiePrivate::expirationDate

◆ httpOnly

bool QNetworkCookiePrivate::httpOnly

Definition at line 73 of file qnetworkcookie_p.h.

Referenced by QNetworkCookie::isHttpOnly(), and QNetworkCookie::setHttpOnly().

◆ name

QByteArray QNetworkCookiePrivate::name

◆ path

QString QNetworkCookiePrivate::path

◆ secure

bool QNetworkCookiePrivate::secure

◆ value

QByteArray QNetworkCookiePrivate::value

The documentation for this class was generated from the following files: