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)
403 second =
text.
mid(equalsPosition + 1, secondLength).
trimmed().toByteArray();
447constexpr QByteArrayView sameSiteNone() noexcept {
return "None"; }
449constexpr QByteArrayView sameSiteStrict() noexcept {
return "Strict"; }
455 return sameSiteNone();
457 return sameSiteLax();
459 return sameSiteStrict();
510 "ddd, dd-MMM-yyyy hh:mm:ss 'GMT"_L1).toLatin1();
554static const int zoneOffsets[] = {-8, -8, -7, -7, -6, -6, -5, -5, -4, -3, 0, 0, 0, 1, 2, 9 };
572{
return s >=
'0' &&
s <=
'9'; }
575{
return c ==
'\n' ||
c ==
'\r'; }
581{
return c ==
' ' ||
c ==
'\t'; }
585 if (dateString[
at] <
'a' || dateString[
at] >
'z')
587 if (
val == -1 && dateString.size() >=
at + 3) {
592 if (
str[0] == dateString[
at]
593 &&
str[1] == dateString[
at + 1]
594 &&
str[2] == dateString[
at + 2]) {
598 i += int(strlen(
str)) + 1;
642 u
"(\\d\\d?):(\\d\\d?)(?::(\\d\\d?)(?:\\.(\\d{1,3}))?)?(?:\\s*(am|pm))?"_s);
645 while (
at < dateString.size()) {
646#ifdef PARSEDATESTRINGDEBUG
655#ifdef PARSEDATESTRINGDEBUG
656 qDebug() <<
"Month:" << month;
665 int sign = (
at >= 0 && dateString[
at - 1] ==
'-') ? -1 : 1;
667#ifdef PARSEDATESTRINGDEBUG
668 qDebug() <<
"Zone:" << month;
675 && (zoneOffset == -1 || zoneOffset == 0)
676 && (dateString[
at] ==
'+' || dateString[
at] ==
'-')
679 || dateString[
at - 1] ==
','
681 && (dateString[
at - 3] ==
'g')
682 && (dateString[
at - 2] ==
'm')
683 && (dateString[
at - 1] ==
't')))) {
686 while (
end < 5 && dateString.size() >
at+
end
687 && dateString[
at +
end] >=
'0' && dateString[
at +
end] <=
'9')
693 minutes = dateString.mid(
at + 3, 2).toInt();
696 hours = dateString.mid(
at + 1, 2).toInt();
699 hours = dateString.mid(
at + 1, 1).toInt();
706 int sign = dateString[
at] ==
'-' ? -1 : 1;
707 zoneOffset =
sign * ((minutes * 60) + (hours * 60 * 60));
708#ifdef PARSEDATESTRINGDEBUG
709 qDebug() <<
"Zone offset:" << zoneOffset << hours << minutes;
718 && dateString.size() >=
at + 3
719 && (dateString[
at + 2] ==
':' || dateString[
at + 1] ==
':')) {
725 if (
auto match = timeRx.match(dateToString,
at);
match.hasMatch()) {
726 int h =
match.capturedView(1).toInt();
727 int m =
match.capturedView(2).toInt();
728 int s =
match.capturedView(3).toInt();
729 int ms =
match.capturedView(4).toInt();
731 if (
h < 12 && !ampm.isEmpty())
735#ifdef PARSEDATESTRINGDEBUG
746 && dateString.size() >
at + 3) {
750 year = dateString.mid(
at, 4).toInt();
752#ifdef PARSEDATESTRINGDEBUG
753 qDebug() <<
"Year:" << year;
763 if (dateString.size() >
at + 1
766 int x = dateString.mid(
at,
length).toInt();
767 if (year == -1 && (
x > 31 ||
x == 0)) {
775#ifdef PARSEDATESTRINGDEBUG
788 int couldBe[3] = { 0, 0, 0 };
789 int unknownCount = 3;
790 for (
int i = 0;
i < unknownCount; ++
i) {
813 for (
int i = 0;
i < unknownCount; ++
i) {
816 bool findMatchingDay = couldBe[
i] &
AMONTH;
817 if (!findMatchingMonth || !findMatchingDay)
819 for (
int j = 0;
j < 3; ++
j) {
822 for (
int k = 0; k < 2; ++k) {
823 if (k == 0 && !(findMatchingMonth && (couldBe[
j] &
AMONTH)))
825 else if (k == 1 && !(findMatchingDay && (couldBe[
j] &
ADAY)))
831 if (
m == -1)
m = month;
841 case 4:
case 6:
case 9:
case 11:
846 if (
d > 0 &&
d <= 31)
849 if (k == 0) findMatchingMonth = found;
850 else if (k == 1) findMatchingDay = found;
853 if (findMatchingMonth)
856 couldBe[
i] &= ~AMONTH;
861 for (
int i = 0;
i < unknownCount; ++
i) {
863 for (
int j = 0;
j < 3; ++
j) {
864 if (couldBe[
j] ==
ADAY && day == -1) {
867 }
else if (couldBe[
j] ==
AMONTH && month == -1) {
870 }
else if (couldBe[
j] ==
AYEAR && year == -1) {
877 couldBe[
j] &= ~unset;
882 for (
int i = 0;
i < unknownCount; ++
i) {
887#ifdef PARSEDATESTRINGDEBUG
888 qDebug() <<
"Final set" << year << month << day;
891 if (year == -1 || month == -1 || day == -1) {
892#ifdef PARSEDATESTRINGDEBUG
893 qDebug() <<
"Parser failure" << year << month << day;
917 if (zoneOffset != -1)
941 QList<QNetworkCookie> cookies;
958 QList<QNetworkCookie>
result;
962 const int length = cookieString.size();
968 if (field.first.isEmpty())
976 switch (cookieString.at(
position++)) {
997 if (!rawDomain.isEmpty()) {
999 if (rawDomain.startsWith(
'.')) {
1000 maybeLeadingDot =
"."_L1;
1001 rawDomain = rawDomain.
mid(1);
1006 if (!normalizedDomain.isEmpty()) {
1007 cookie.
setDomain(maybeLeadingDot + normalizedDomain);
1017 int secs = field.second.toInt(&
ok);
1028 if (field.second.startsWith(
'/')) {
1068 QString defaultPath = pathAndFileName.
left(pathAndFileName.lastIndexOf(u
'/') + 1);
1069 if (defaultPath.isEmpty())
1071 d->
path = defaultPath;
1090#ifndef QT_NO_DEBUG_STREAM
1094 s.resetFormat().nospace();
1102#include "moc_qnetworkcookie.cpp"
static constexpr auto IPv4Protocol
static constexpr auto IPv6Protocol
QByteArray trimmed() const &
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 &
\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.
constexpr auto tokenize(Needle &&needle, Flags...flags) const noexcept(noexcept(qTokenize(std::declval< const QLatin1StringView & >(), std::forward< Needle >(needle), flags...))) -> decltype(qTokenize(*this, std::forward< Needle >(needle), flags...))
constexpr QLatin1StringView mid(qsizetype pos, qsizetype n=-1) const
static QLocale c()
Returns a QLocale object initialized to the "C" locale.
static QList< QNetworkCookie > parseSetCookieHeaderLine(QByteArrayView 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.
static QList< QNetworkCookie > parseCookies(QByteArrayView cookieString)
Parses the cookie string cookieString as received from a server response in the "Set-Cookie:" header.
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.
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
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString left(qsizetype n) const &
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
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...
QString mid(qsizetype position, qsizetype n=-1) const &
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
qsizetype size() const noexcept
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...
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
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.
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QPair< QByteArray, QByteArray > nextField(QByteArrayView text, int &position, bool isNameValue)
static const char months[]
QDebug operator<<(QDebug s, const QNetworkCookie &cookie)
static bool checkStaticArray(int &val, QByteArrayView dateString, int at, const char *array, int size)
static bool isValueSeparator(char c)
static bool isWhitespace(char c)
static QDateTime parseDateString(QByteArrayView dateString)
static const int zoneOffsets[]
static bool isNumber(char s)
static bool isTerminator(char c)
static const char zones[]
static int nextNonWhitespace(QByteArrayView text, int from)
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLfloat GLfloat GLfloat GLfloat h
GLsizei const GLchar *const * path
QT_BEGIN_NAMESPACE 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[]
QT_BEGIN_NAMESPACE constexpr void qSwap(T &value1, T &value2) noexcept(std::is_nothrow_swappable_v< T >)
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
QUrl url("example.com")
[constructor-url-reference]