47 #include "QtCore/qbytearray.h" 48 #include "QtCore/qdebug.h" 49 #include "QtCore/qlist.h" 50 #include "QtCore/qlocale.h" 51 #include "QtCore/qstring.h" 52 #include "QtCore/qstringlist.h" 53 #include "QtCore/qurl.h" 54 #include "private/qobject_p.h" 112 qRegisterMetaType<QNetworkCookie>();
113 qRegisterMetaType<QList<QNetworkCookie> >();
346 d->
name = cookieName;
381 const int length = text.
length();
385 for (i = position; i < length; ++i) {
386 register char c = text.
at(i);
387 if (c ==
';' || c ==
'=')
396 if (i == length || text.
at(i) !=
'=')
404 if (i < length && text.
at(i) ==
'"') {
416 register char c = text.
at(i);
422 }
else if (c ==
'\\') {
436 for ( ; i < length; ++i) {
437 register char c = text.
at(i);
445 for ( ; i < length; ++i) {
446 register char c = text.
at(i);
449 if (c ==
';' || ((isNameValue && (c ==
'\n' || c ==
'\r')) || (!isNameValue &&
isLWS(c))))
453 second = text.
mid(position, i - position).
trimmed();
522 result +=
"; secure";
524 result +=
"; HttpOnly";
526 result +=
"; expires=";
531 result +=
"; domain=";
535 domainNoDot = domainNoDot.
mid(1);
565 static int zoneOffsets[] = {-8, -8, -7, -7, -6, -6, -5, -5, -4, -3, 0, 0, 0, 1, 2, 9 };
583 {
return s >=
'0' && s <=
'9'; }
586 {
return c ==
'\n' || c ==
'\r'; }
592 {
return c ==
' ' || c ==
'\t'; }
596 if (dateString[at] <
'a' || dateString[at] >
'z')
598 if (val == -1 && dateString.
length() >= at + 3) {
602 const char *str = array + i;
603 if (str[0] == dateString[at]
604 && str[1] == dateString[at + 1]
605 && str[2] == dateString[at + 2]) {
609 i += strlen(str) + 1;
645 int unknown[3] = {-1, -1, -1};
652 QRegExp timeRx(
QLatin1String(
"(\\d{1,2}):(\\d{1,2})(:(\\d{1,2})|)(\\.(\\d{1,3})|)((\\s{0,}(am|pm))|)"));
655 while (at < dateString.
length()) {
656 #ifdef PARSEDATESTRINGDEBUG 659 bool isNum =
isNumber(dateString[at]);
665 #ifdef PARSEDATESTRINGDEBUG 666 qDebug() <<
"Month:" << month;
675 int sign = (at >= 0 && dateString[at - 1] ==
'-') ? -1 : 1;
676 zoneOffset = sign *
zoneOffsets[zoneOffset] * 60 * 60;
677 #ifdef PARSEDATESTRINGDEBUG 678 qDebug() <<
"Zone:" << month;
685 && (zoneOffset == -1 || zoneOffset == 0)
686 && (dateString[at] ==
'+' || dateString[at] ==
'-')
689 || dateString[at - 1] ==
',' 691 && (dateString[at - 3] ==
'g')
692 && (dateString[at - 2] ==
'm')
693 && (dateString[at - 1] ==
't')))) {
696 while (end < 5 && dateString.
length() > at+end
697 && dateString[at +
end] >=
'0' && dateString[at +
end] <=
'9')
703 minutes = atoi(dateString.mid(at + 3, 2).constData());
706 hours = atoi(dateString.mid(at + 1, 2).constData());
709 hours = atoi(dateString.mid(at + 1, 1).constData());
716 int sign = dateString[
at] ==
'-' ? -1 : 1;
717 zoneOffset = sign * ((minutes * 60) + (hours * 60 * 60));
718 #ifdef PARSEDATESTRINGDEBUG 719 qDebug() <<
"Zone offset:" << zoneOffset << hours << minutes;
727 if (isNum && time.
isNull()
728 && dateString.
length() >= at + 3
729 && (dateString[at + 2] ==
':' || dateString[at + 1] ==
':')) {
742 time =
QTime(h, m, s, ms);
743 #ifdef PARSEDATESTRINGDEBUG 754 && dateString.length() > at + 3) {
758 year = atoi(dateString.mid(at, 4).constData());
760 #ifdef PARSEDATESTRINGDEBUG 761 qDebug() <<
"Year:" << year;
771 if (dateString.length() > at + 1
774 int x = atoi(dateString.mid(at, length).constData());
775 if (year == -1 && (x > 31 || x == 0)) {
778 if (unknown[0] == -1) unknown[0] = x;
779 else if (unknown[1] == -1) unknown[1] = x;
780 else if (unknown[2] == -1) unknown[2] = x;
783 #ifdef PARSEDATESTRINGDEBUG 784 qDebug() <<
"Saving" << x;
796 int couldBe[3] = { 0, 0, 0 };
797 int unknownCount = 3;
798 for (
int i = 0; i < unknownCount; ++i) {
799 if (unknown[i] == -1) {
808 if (month == -1 && unknown[i] >= 1 && unknown[i] <= 12)
821 for (
int i = 0; i < unknownCount; ++i) {
822 int currentValue = unknown[i];
823 bool findMatchingMonth = couldBe[i] &
ADAY && currentValue >= 29;
824 bool findMatchingDay = couldBe[i] &
AMONTH;
825 if (!findMatchingMonth || !findMatchingDay)
827 for (
int j = 0; j < 3; ++j) {
830 for (
int k = 0; k < 2; ++k) {
831 if (k == 0 && !(findMatchingMonth && (couldBe[j] & AMONTH)))
833 else if (k == 1 && !(findMatchingDay && (couldBe[j] &
ADAY)))
835 int m = currentValue;
839 if (m == -1) m = month;
849 case 4:
case 6:
case 9:
case 11:
854 if (d > 0 && d <= 31)
857 if (k == 0) findMatchingMonth = found;
858 else if (k == 1) findMatchingDay = found;
861 if (findMatchingMonth)
864 couldBe[i] &= ~AMONTH;
869 for (
int i = 0; i < unknownCount; ++i) {
871 for (
int j = 0; j < 3; ++j) {
872 if (couldBe[j] ==
ADAY && day == -1) {
875 }
else if (couldBe[j] ==
AMONTH && month == -1) {
878 }
else if (couldBe[j] ==
AYEAR && year == -1) {
885 couldBe[j] &= ~unset;
890 for (
int i = 0; i < unknownCount; ++i) {
891 if (couldBe[i] &
AMONTH && month == -1) month = unknown[i];
892 else if (couldBe[i] &
ADAY && day == -1) day = unknown[i];
893 else if (couldBe[i] &
AYEAR && year == -1) year = unknown[i];
895 #ifdef PARSEDATESTRINGDEBUG 896 qDebug() <<
"Final set" << year << month << day;
899 if (year == -1 || month == -1 || day == -1) {
900 #ifdef PARSEDATESTRINGDEBUG 901 qDebug() <<
"Parser failure" << year << month << day;
913 QDate date(year + y2k, month, day);
921 date =
QDate(day + y2k, month, year);
925 if (zoneOffset != -1) {
926 dateTime = dateTime.
addSecs(zoneOffset);
950 for (
int a = 0;
a < list.
size();
a++)
970 const int length = cookieString.
length();
971 while (position < length) {
983 while (position < length) {
984 switch (cookieString.
at(position++)) {
987 field =
nextField(cookieString, position,
false);
990 if (field.
first ==
"expires") {
993 for (end = position; end < length; ++
end)
1004 }
else if (field.
first ==
"domain") {
1009 rawDomain = rawDomain.
mid(1);
1015 cookie.
setDomain(maybeLeadingDot + normalizedDomain);
1016 }
else if (field.
first ==
"max-age") {
1022 }
else if (field.
first ==
"path") {
1025 }
else if (field.
first ==
"secure") {
1027 }
else if (field.
first ==
"httponly") {
1029 }
else if (field.
first ==
"comment") {
1031 }
else if (field.
first ==
"version") {
1032 if (field.
second !=
"1") {
1052 #ifndef QT_NO_DEBUG_STREAM QDateTime addSecs(int secs) const
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or...
The QDebug class provides an output stream for debugging information.
static QString fromPercentEncoding(const QByteArray &)
Returns a decoded copy of input.
static QList< QNetworkCookie > parseSetCookieHeaderLine(const QByteArray &cookieString)
void setExpirationDate(const QDateTime &date)
Sets the expiration date of this cookie to date.
QString domain() const
Returns the domain this cookie is associated with.
static QByteArray toPercentEncoding(const QString &, const QByteArray &exclude=QByteArray(), const QByteArray &include=QByteArray())
Returns an encoded copy of input.
#define QT_END_NAMESPACE
This macro expands to.
QDebug operator<<(QDebug s, const QNetworkCookie &cookie)
bool isSessionCookie() const
Returns true if this cookie is a session cookie.
QSharedDataPointer< QNetworkCookiePrivate > d
The QRegExp class provides pattern matching using regular expressions.
bool isValid() const
Returns true if this date is valid; otherwise returns false.
bool isNull() const
Returns true if the time is null (i.
QDebug & nospace()
Clears the stream's internal flag that records whether the last character was a space and returns a r...
#define at(className, varName)
The QByteArray class provides an array of bytes.
void setHttpOnly(bool enable)
Sets this cookie's "HttpOnly" flag to enable.
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
int matchedLength() const
Returns the length of the last matched string, or -1 if there was no match.
static bool isWhitespace(char c)
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
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.
void setDomain(const QString &domain)
Sets the domain associated with this cookie to be domain.
The QDate class provides date functions.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool isNumber(char s)
long ASN1_INTEGER_get ASN1_INTEGER * a
void setPath(const QString &path)
Sets the path associated with this cookie to be path.
RawForm
This enum is used with the toRawForm() function to declare which form of a cookie shall be returned...
The QString class provides a Unicode character string.
bool startsWith(const QByteArray &a) const
Returns true if this byte array starts with byte array ba; otherwise returns false.
~QNetworkCookie()
Destroys this QNetworkCookie object.
static int nextNonWhitespace(const QByteArray &text, int from)
QString toString(qlonglong i) const
Returns a localized string representation of i.
static QList< QNetworkCookie > parseCookies(const QByteArray &cookieString)
Parses the cookie string cookieString as received from a server response in the "Set-Cookie:" header...
bool operator==(const QNetworkCookie &other) const
Returns true if this cookie is equal to other.
Q_CORE_EXPORT void qDebug(const char *,...)
QByteArray toRawForm(RawForm form=Full) const
Returns the raw form of this QNetworkCookie.
static QByteArray toAce(const QString &)
Returns the ASCII Compatible Encoding of the given domain name domain.
static bool isValueSeparator(char c)
The QTime class provides clock time functions.
#define QT_BEGIN_NAMESPACE
This macro expands to.
void setName(const QByteArray &cookieName)
Sets the name of this cookie to be cookieName.
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
QString path() const
Returns the path associated with this cookie.
static QDateTime parseDateString(const QByteArray &dateString)
QStringList capturedTexts() const
Returns a list of the captured text strings.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QNetworkCookie(const QByteArray &name=QByteArray(), const QByteArray &value=QByteArray())
Create a new QNetworkCookie object, initializing the cookie name to name and its value to value...
void setSecure(bool enable)
Sets the secure flag of this cookie to enable.
QDateTime expirationDate() const
Returns the expiration date for this cookie.
QByteArray trimmed() const
Returns a byte array that has whitespace removed from the start and the end.
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
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 bool isLWS(register char c)
static QString fromAce(const QByteArray &)
Returns the Unicode form of the given domain name domain, which is encoded in the ASCII Compatible En...
void qSwap(T &value1, T &value2)
QDateTime toUTC() const
Returns a datetime containing the date and time information in this datetime, but specified using the...
int length() const
Same as size().
The QNetworkCookie class holds one network cookie.
static QPair< QByteArray, QByteArray > nextField(const QByteArray &text, int &position, bool isNameValue)
const char * constData() const
Returns a pointer to the data stored in the byte array.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays...
static QLocale c()
Returns a QLocale object initialized to the "C" locale.
The QDateTime class provides date and time functions.
bool isHttpOnly() const
Returns true if the "HttpOnly" flag is enabled for this cookie.
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...
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
void resize(int size)
Sets the size of the byte array to size bytes.
QByteArray name() const
Returns the name of this cookie.
int size() const
Returns the number of items in the list.
static QDateTime currentDateTime()
Returns the current datetime, as reported by the system clock, in the local time zone.
bool isSecure() const
Returns true if the "secure" option was specified in the cookie string, false otherwise.
static bool checkStaticArray(int &val, const QByteArray &dateString, int at, const char *array, int size)
QNetworkCookie & operator=(const QNetworkCookie &other)
Copies the contents of the QNetworkCookie object other to this object.
QByteArray & replace(int index, int len, const char *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static const char months[]
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
QByteArray value() const
Returns this cookies value, as specified in the cookie string.
char at(int i) const
Returns the character at index position i in the byte array.
void reserve(int size)
Attempts to allocate memory for at least size bytes.
static const KeyPair *const end
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
void setValue(const QByteArray &value)
Sets the value of this cookie to be value.
static const char zones[]
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.
static bool isTerminator(char c)