9#include "QtCore/qbytearray.h"
10#include "QtCore/qdatetime.h"
11#include "QtCore/qdebug.h"
12#include "QtCore/qlist.h"
13#include "QtCore/qlocale.h"
14#include <QtCore/qregularexpression.h>
15#include "QtCore/qstring.h"
16#include "QtCore/qstringlist.h"
17#include "QtCore/qtimezone.h"
18#include "QtCore/qurl.h"
19#include "QtNetwork/qhostaddress.h"
20#include "private/qobject_p.h"
82 qRegisterMetaType<QNetworkCookie>();
83 qRegisterMetaType<QList<QNetworkCookie> >();
351 d->
name = cookieName;
389 if (semiColonPosition < 0)
390 semiColonPosition =
length;
393 if (equalsPosition < 0 || equalsPosition > semiColonPosition) {
396 equalsPosition = semiColonPosition;
401 int secondLength = semiColonPosition - equalsPosition - 1;
402 if (secondLength > 0)
506 "ddd, dd-MMM-yyyy hh:mm:ss 'GMT"_L1).
toLatin1();
550static const int zoneOffsets[] = {-8, -8, -7, -7, -6, -6, -5, -5, -4, -3, 0, 0, 0, 1, 2, 9 };
568{
return s >=
'0' &&
s <=
'9'; }
571{
return c ==
'\n' ||
c ==
'\r'; }
577{
return c ==
' ' ||
c ==
'\t'; }
581 if (dateString[
at] <
'a' || dateString[
at] >
'z')
583 if (
val == -1 && dateString.
size() >=
at + 3) {
588 if (
str[0] == dateString[
at]
589 &&
str[1] == dateString[
at + 1]
590 &&
str[2] == dateString[
at + 2]) {
594 i += int(strlen(
str)) + 1;
638 u
"(\\d\\d?):(\\d\\d?)(?::(\\d\\d?)(?:\\.(\\d{1,3}))?)?(?:\\s*(am|pm))?"_s);
641 while (
at < dateString.
size()) {
642#ifdef PARSEDATESTRINGDEBUG
651#ifdef PARSEDATESTRINGDEBUG
652 qDebug() <<
"Month:" << month;
661 int sign = (
at >= 0 && dateString[
at - 1] ==
'-') ? -1 : 1;
663#ifdef PARSEDATESTRINGDEBUG
664 qDebug() <<
"Zone:" << month;
671 && (zoneOffset == -1 || zoneOffset == 0)
672 && (dateString[
at] ==
'+' || dateString[
at] ==
'-')
675 || dateString[
at - 1] ==
','
677 && (dateString[
at - 3] ==
'g')
678 && (dateString[
at - 2] ==
'm')
679 && (dateString[
at - 1] ==
't')))) {
683 && dateString[
at +
end] >=
'0' && dateString[
at +
end] <=
'9')
702 int sign = dateString[
at] ==
'-' ? -1 : 1;
703 zoneOffset =
sign * ((minutes * 60) + (hours * 60 * 60));
704#ifdef PARSEDATESTRINGDEBUG
705 qDebug() <<
"Zone offset:" << zoneOffset << hours << minutes;
714 && dateString.
size() >=
at + 3
715 && (dateString[
at + 2] ==
':' || dateString[
at + 1] ==
':')) {
722 int h =
match.capturedView(1).toInt();
723 int m =
match.capturedView(2).toInt();
724 int s =
match.capturedView(3).toInt();
725 int ms =
match.capturedView(4).toInt();
731#ifdef PARSEDATESTRINGDEBUG
742 && dateString.
size() >
at + 3) {
748#ifdef PARSEDATESTRINGDEBUG
749 qDebug() <<
"Year:" << year;
759 if (dateString.
size() >
at + 1
763 if (year == -1 && (
x > 31 ||
x == 0)) {
771#ifdef PARSEDATESTRINGDEBUG
784 int couldBe[3] = { 0, 0, 0 };
785 int unknownCount = 3;
786 for (
int i = 0;
i < unknownCount; ++
i) {
809 for (
int i = 0;
i < unknownCount; ++
i) {
812 bool findMatchingDay = couldBe[
i] &
AMONTH;
813 if (!findMatchingMonth || !findMatchingDay)
815 for (
int j = 0;
j < 3; ++
j) {
818 for (
int k = 0; k < 2; ++k) {
819 if (k == 0 && !(findMatchingMonth && (couldBe[
j] &
AMONTH)))
821 else if (k == 1 && !(findMatchingDay && (couldBe[
j] &
ADAY)))
827 if (
m == -1)
m = month;
837 case 4:
case 6:
case 9:
case 11:
842 if (
d > 0 &&
d <= 31)
845 if (k == 0) findMatchingMonth = found;
846 else if (k == 1) findMatchingDay = found;
849 if (findMatchingMonth)
852 couldBe[
i] &= ~AMONTH;
857 for (
int i = 0;
i < unknownCount; ++
i) {
859 for (
int j = 0;
j < 3; ++
j) {
860 if (couldBe[
j] ==
ADAY && day == -1) {
863 }
else if (couldBe[
j] ==
AMONTH && month == -1) {
866 }
else if (couldBe[
j] ==
AYEAR && year == -1) {
873 couldBe[
j] &= ~unset;
878 for (
int i = 0;
i < unknownCount; ++
i) {
883#ifdef PARSEDATESTRINGDEBUG
884 qDebug() <<
"Final set" << year << month << day;
887 if (year == -1 || month == -1 || day == -1) {
888#ifdef PARSEDATESTRINGDEBUG
889 qDebug() <<
"Parser failure" << year << month << day;
913 if (zoneOffset != -1)
964 if (field.first.isEmpty())
976 field.first = field.first.toLower();
978 if (field.first ==
"expires") {
991 }
else if (field.first ==
"domain") {
997 maybeLeadingDot = u
'.';
998 rawDomain = rawDomain.
mid(1);
1003 if (!normalizedDomain.
isEmpty()) {
1004 cookie.
setDomain(maybeLeadingDot + normalizedDomain);
1012 }
else if (field.first ==
"max-age") {
1014 int secs = field.second.toInt(&
ok);
1024 }
else if (field.first ==
"path") {
1025 if (field.second.startsWith(
'/')) {
1034 }
else if (field.first ==
"secure") {
1036 }
else if (field.first ==
"httponly") {
1038 }
else if (field.first ==
"samesite") {
1068 d->
path = defaultPath;
1087#ifndef QT_NO_DEBUG_STREAM
1091 s.resetFormat().nospace();
1099#include "moc_qnetworkcookie.cpp"
static constexpr auto IPv4Protocol
static constexpr auto IPv6Protocol
QByteArray trimmed() const &
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays.
bool startsWith(QByteArrayView bv) const
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
QByteArray toLower() const &
QByteArray mid(qsizetype index, qsizetype len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos.
\inmodule QtCore\reentrant
static QDateTime fromSecsSinceEpoch(qint64 secs, const QTimeZone &timeZone)
QDateTime toUTC() const
Returns a copy of this datetime converted to UTC.
QDateTime addSecs(qint64 secs) const
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or...
bool isValid() const
Returns true if this datetime represents a definite moment, otherwise false.
static QDateTime currentDateTimeUtc()
\inmodule QtCore \reentrant
constexpr bool isValid() const
Returns true if this date is valid; otherwise returns false.
The QHostAddress class provides an IP address.
NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
static QLocale c()
Returns a QLocale object initialized to the "C" locale.
QString toString(qlonglong i) const
Returns a localized string representation of i.
static QList< QNetworkCookie > parseSetCookieHeaderLine(const QByteArray &cookieString)
QNetworkCookie::SameSite sameSite
The QNetworkCookie class holds one network cookie.
bool isSessionCookie() const
Returns true if this cookie is a session cookie.
SameSite sameSitePolicy() const
Returns the "SameSite" option if specified in the cookie string, SameSite::Default if not present.
bool hasSameIdentifier(const QNetworkCookie &other) const
Returns true if this cookie has the same identifier tuple as other.
QString domain() const
Returns the domain this cookie is associated with.
QByteArray name() const
Returns the name of this cookie.
QByteArray value() const
Returns this cookies value, as specified in the cookie string.
void setPath(const QString &path)
Sets the path associated with this cookie to be path.
bool isSecure() const
Returns true if the "secure" option was specified in the cookie string, false otherwise.
void normalize(const QUrl &url)
QDateTime expirationDate() const
Returns the expiration date for this cookie.
void setSecure(bool enable)
Sets the secure flag of this cookie to enable.
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
QByteArray toRawForm(RawForm form=Full) const
Returns the raw form of this QNetworkCookie.
void setDomain(const QString &domain)
Sets the domain associated with this cookie to be domain.
void setValue(const QByteArray &value)
Sets the value of this cookie to be value.
void setSameSitePolicy(SameSite sameSite)
Sets the "SameSite" option of this cookie to sameSite.
void setHttpOnly(bool enable)
QString path() const
Returns the path associated with this cookie.
RawForm
This enum is used with the toRawForm() function to declare which form of a cookie shall be returned.
QNetworkCookie & operator=(QNetworkCookie &&other) noexcept
void setName(const QByteArray &cookieName)
Sets the name of this cookie to be cookieName.
void setExpirationDate(const QDateTime &date)
Sets the expiration date of this cookie to date.
~QNetworkCookie()
Destroys this QNetworkCookie object.
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.
\inmodule QtCore \reentrant
QRegularExpressionMatch match(const QString &subject, qsizetype offset=0, MatchType matchType=NormalMatch, MatchOptions matchOptions=NoMatchOption) const
Attempts to match the regular expression against the given subject string, starting at the position o...
constexpr bool isEmpty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype size() const
Returns the number of characters in this string.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString toLower() const &
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString trimmed() const &
QByteArray toUtf8() const &
QString & prepend(QChar c)
\inmodule QtCore \reentrant
constexpr bool isNull() const
Returns true if the time is null (i.e., the QTime object was constructed using the default constructo...
static QByteArray toAce(const QString &domain, AceProcessingOptions options={})
QString host(ComponentFormattingOptions=FullyDecoded) const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
static QString fromAce(const QByteArray &domain, AceProcessingOptions options={})
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
Combined button and popup list for selecting options.
#define QByteArrayLiteral(str)
std::pair< T1, T2 > QPair
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QPair< QByteArray, QByteArray > nextField(const QByteArray &text, int &position, bool isNameValue)
static const char months[]
QDebug operator<<(QDebug s, const QNetworkCookie &cookie)
static bool isValueSeparator(char c)
static bool isWhitespace(char c)
static QDateTime parseDateString(const QByteArray &dateString)
static bool checkStaticArray(int &val, const QByteArray &dateString, int at, const char *array, int size)
static const int zoneOffsets[]
static bool isNumber(char s)
static bool isTerminator(char c)
static const char zones[]
static int nextNonWhitespace(const QByteArray &text, int from)
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLfloat GLfloat GLfloat GLfloat h
GLsizei const GLchar *const * path
constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static const struct ImageFormatTab unknown[]
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
QUrl url("example.com")
[constructor-url-reference]