QtNetwork: use const (and const APIs) more
For CoW types, prefer const methods to avoid needless detach()ing. Mark predictNextRequest() as const, because this method does not modify the object. Change-Id: Ic94e2b31445ece46ab1423bf5b5f4e66d9a5b6ca Reviewed-by: Edward Welbourne <edward.welbourne@theqtcompany.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>bb10
parent
c003a18ee3
commit
01d526d18b
|
|
@ -542,7 +542,7 @@ static void _q_parseUnixDir(const QStringList &tokens, const QString &userName,
|
|||
|
||||
// Resolve permissions
|
||||
int permissions = 0;
|
||||
QString p = tokens.at(2);
|
||||
const QString &p = tokens.at(2);
|
||||
permissions |= (p[0] == QLatin1Char('r') ? QUrlInfo::ReadOwner : 0);
|
||||
permissions |= (p[1] == QLatin1Char('w') ? QUrlInfo::WriteOwner : 0);
|
||||
permissions |= (p[2] == QLatin1Char('x') ? QUrlInfo::ExeOwner : 0);
|
||||
|
|
@ -947,7 +947,7 @@ void QFtpPI::readyRead()
|
|||
const int lowerLimit[3] = {1,0,0};
|
||||
const int upperLimit[3] = {5,5,9};
|
||||
for (int i=0; i<3; i++) {
|
||||
replyCode[i] = line[i].digitValue();
|
||||
replyCode[i] = line.at(i).digitValue();
|
||||
if (replyCode[i]<lowerLimit[i] || replyCode[i]>upperLimit[i]) {
|
||||
// protocol error
|
||||
return;
|
||||
|
|
@ -1072,7 +1072,7 @@ bool QFtpPI::processReply()
|
|||
#endif
|
||||
// this error should be reported
|
||||
} else {
|
||||
QStringList lst = addrPortPattern.capturedTexts();
|
||||
const QStringList lst = addrPortPattern.capturedTexts();
|
||||
QString host = lst[1] + QLatin1Char('.') + lst[2] + QLatin1Char('.') + lst[3] + QLatin1Char('.') + lst[4];
|
||||
quint16 port = (lst[5].toUInt() << 8) + lst[6].toUInt();
|
||||
waitForDtpToConnect = true;
|
||||
|
|
@ -1098,7 +1098,7 @@ bool QFtpPI::processReply()
|
|||
|
||||
} else if (replyCodeInt == 230) {
|
||||
if (currentCmd.startsWith(QLatin1String("USER ")) && pendingCommands.count()>0 &&
|
||||
pendingCommands.first().startsWith(QLatin1String("PASS "))) {
|
||||
pendingCommands.constFirst().startsWith(QLatin1String("PASS "))) {
|
||||
// no need to send the PASS -- we are already logged in
|
||||
pendingCommands.pop_front();
|
||||
}
|
||||
|
|
@ -1177,7 +1177,7 @@ bool QFtpPI::startNextCmd()
|
|||
emit finished(replyText);
|
||||
return false;
|
||||
}
|
||||
currentCmd = pendingCommands.first();
|
||||
currentCmd = pendingCommands.constFirst();
|
||||
|
||||
// PORT and PASV are edited in-place, depending on whether we
|
||||
// should try the extended transfer connection commands EPRT and
|
||||
|
|
@ -2241,7 +2241,7 @@ void QFtpPrivate::_q_startNextCommand()
|
|||
Q_Q(QFtp);
|
||||
if (pending.isEmpty())
|
||||
return;
|
||||
QFtpCommand *c = pending.first();
|
||||
QFtpCommand *c = pending.constFirst();
|
||||
|
||||
error = QFtp::NoError;
|
||||
errorString = QT_TRANSLATE_NOOP(QFtp, QLatin1String("Unknown error"));
|
||||
|
|
@ -2253,7 +2253,7 @@ void QFtpPrivate::_q_startNextCommand()
|
|||
// Proxy support, replace the Login argument in place, then fall
|
||||
// through.
|
||||
if (c->command == QFtp::Login && !proxyHost.isEmpty()) {
|
||||
QString loginString = c->rawCmds.first().trimmed();
|
||||
QString loginString = c->rawCmds.constFirst().trimmed();
|
||||
loginString += QLatin1Char('@') + host;
|
||||
if (port && port != 21)
|
||||
loginString += QLatin1Char(':') + QString::number(port);
|
||||
|
|
@ -2264,8 +2264,8 @@ void QFtpPrivate::_q_startNextCommand()
|
|||
if (c->command == QFtp::SetTransferMode) {
|
||||
_q_piFinished(QLatin1String("Transfer mode set"));
|
||||
} else if (c->command == QFtp::SetProxy) {
|
||||
proxyHost = c->rawCmds[0];
|
||||
proxyPort = c->rawCmds[1].toUInt();
|
||||
proxyHost = c->rawCmds.at(0);
|
||||
proxyPort = c->rawCmds.at(1).toUInt();
|
||||
c->rawCmds.clear();
|
||||
_q_piFinished(QLatin1String("Proxy set to ") + proxyHost + QLatin1Char(':') + QString::number(proxyPort));
|
||||
} else if (c->command == QFtp::ConnectToHost) {
|
||||
|
|
@ -2274,11 +2274,11 @@ void QFtpPrivate::_q_startNextCommand()
|
|||
pi.setProperty("_q_networksession", q->property("_q_networksession"));
|
||||
#endif
|
||||
if (!proxyHost.isEmpty()) {
|
||||
host = c->rawCmds[0];
|
||||
port = c->rawCmds[1].toUInt();
|
||||
host = c->rawCmds.at(0);
|
||||
port = c->rawCmds.at(1).toUInt();
|
||||
pi.connectToHost(proxyHost, proxyPort);
|
||||
} else {
|
||||
pi.connectToHost(c->rawCmds[0], c->rawCmds[1].toUInt());
|
||||
pi.connectToHost(c->rawCmds.at(0), c->rawCmds.at(1).toUInt());
|
||||
}
|
||||
} else {
|
||||
if (c->command == QFtp::Put) {
|
||||
|
|
@ -2313,7 +2313,7 @@ void QFtpPrivate::_q_piFinished(const QString&)
|
|||
{
|
||||
if (pending.isEmpty())
|
||||
return;
|
||||
QFtpCommand *c = pending.first();
|
||||
QFtpCommand *c = pending.constFirst();
|
||||
|
||||
if (c->command == QFtp::Close) {
|
||||
// The order of in which the slots are called is arbitrary, so
|
||||
|
|
@ -2348,7 +2348,7 @@ void QFtpPrivate::_q_piError(int errorCode, const QString &text)
|
|||
return;
|
||||
}
|
||||
|
||||
QFtpCommand *c = pending.first();
|
||||
QFtpCommand *c = pending.constFirst();
|
||||
|
||||
// non-fatal errors
|
||||
if (c->command == QFtp::Get && pi.currentCommand().startsWith(QLatin1String("SIZE "))) {
|
||||
|
|
|
|||
|
|
@ -691,7 +691,7 @@ bool QHttpNetworkConnectionPrivate::dequeueRequest(QAbstractSocket *socket)
|
|||
return false;
|
||||
}
|
||||
|
||||
QHttpNetworkRequest QHttpNetworkConnectionPrivate::predictNextRequest()
|
||||
QHttpNetworkRequest QHttpNetworkConnectionPrivate::predictNextRequest() const
|
||||
{
|
||||
if (!highPriorityQueue.isEmpty())
|
||||
return highPriorityQueue.last().first;
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ public:
|
|||
void requeueRequest(const HttpMessagePair &pair); // e.g. after pipeline broke
|
||||
bool dequeueRequest(QAbstractSocket *socket);
|
||||
void prepareRequest(HttpMessagePair &request);
|
||||
QHttpNetworkRequest predictNextRequest();
|
||||
QHttpNetworkRequest predictNextRequest() const;
|
||||
|
||||
void fillPipeline(QAbstractSocket *socket);
|
||||
bool fillPipeline(QList<HttpMessagePair> &queue, QHttpNetworkConnectionChannel &channel);
|
||||
|
|
|
|||
|
|
@ -76,11 +76,11 @@ static void qt_qdnsmailexchangerecord_sort(QList<QDnsMailExchangeRecord> &record
|
|||
|
||||
// Determine the slice of records with the current preference.
|
||||
QList<QDnsMailExchangeRecord> slice;
|
||||
const quint16 slicePreference = records[i].preference();
|
||||
const quint16 slicePreference = records.at(i).preference();
|
||||
for (int j = i; j < records.size(); ++j) {
|
||||
if (records[j].preference() != slicePreference)
|
||||
if (records.at(j).preference() != slicePreference)
|
||||
break;
|
||||
slice << records[j];
|
||||
slice << records.at(j);
|
||||
}
|
||||
|
||||
// Randomize the slice of records.
|
||||
|
|
@ -119,13 +119,13 @@ static void qt_qdnsservicerecord_sort(QList<QDnsServiceRecord> &records)
|
|||
|
||||
// Determine the slice of records with the current priority.
|
||||
QList<QDnsServiceRecord> slice;
|
||||
const quint16 slicePriority = records[i].priority();
|
||||
const quint16 slicePriority = records.at(i).priority();
|
||||
unsigned int sliceWeight = 0;
|
||||
for (int j = i; j < records.size(); ++j) {
|
||||
if (records[j].priority() != slicePriority)
|
||||
if (records.at(j).priority() != slicePriority)
|
||||
break;
|
||||
sliceWeight += records[j].weight();
|
||||
slice << records[j];
|
||||
sliceWeight += records.at(j).weight();
|
||||
slice << records.at(j);
|
||||
}
|
||||
#ifdef QDNSLOOKUP_DEBUG
|
||||
qDebug("qt_qdnsservicerecord_sort() : priority %i (size: %i, total weight: %i)",
|
||||
|
|
@ -137,15 +137,15 @@ static void qt_qdnsservicerecord_sort(QList<QDnsServiceRecord> &records)
|
|||
const unsigned int weightThreshold = qrand() % (sliceWeight + 1);
|
||||
unsigned int summedWeight = 0;
|
||||
for (int j = 0; j < slice.size(); ++j) {
|
||||
summedWeight += slice[j].weight();
|
||||
summedWeight += slice.at(j).weight();
|
||||
if (summedWeight >= weightThreshold) {
|
||||
#ifdef QDNSLOOKUP_DEBUG
|
||||
qDebug("qt_qdnsservicerecord_sort() : adding %s %i (weight: %i)",
|
||||
qPrintable(slice[j].target()), slice[j].port(),
|
||||
slice[j].weight());
|
||||
qPrintable(slice.at(j).target()), slice.at(j).port(),
|
||||
slice.at(j).weight());
|
||||
#endif
|
||||
// Adjust the slice weight and take the current record.
|
||||
sliceWeight -= slice[j].weight();
|
||||
sliceWeight -= slice.at(j).weight();
|
||||
records[i++] = slice.takeAt(j);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ public:
|
|||
|
||||
QNetworkProxy applicationProxy()
|
||||
{
|
||||
return proxyForQuery(QNetworkProxyQuery()).first();
|
||||
return proxyForQuery(QNetworkProxyQuery()).constFirst();
|
||||
}
|
||||
|
||||
QList<QNetworkProxy> proxyForQuery(const QNetworkProxyQuery &query);
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ static QList<QNetworkProxy> parseServerList(const QNetworkProxyQuery &query, con
|
|||
|
||||
result << QNetworkProxy(proxyType, entry.mid(server, pos - server), port);
|
||||
if (!protocolTag.isEmpty())
|
||||
taggedProxies.insert(protocolTag.toString(), result.last());
|
||||
taggedProxies.insert(protocolTag.toString(), result.constLast());
|
||||
}
|
||||
|
||||
if (checkTags && taggedProxies.contains(requiredTag)) {
|
||||
|
|
|
|||
|
|
@ -625,7 +625,7 @@ static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d,
|
|||
mreq4.imr_multiaddr.s_addr = htonl(groupAddress.toIPv4Address());
|
||||
|
||||
if (interface.isValid()) {
|
||||
QList<QNetworkAddressEntry> addressEntries = interface.addressEntries();
|
||||
const QList<QNetworkAddressEntry> addressEntries = interface.addressEntries();
|
||||
if (!addressEntries.isEmpty()) {
|
||||
QHostAddress firstIP = addressEntries.first().ip();
|
||||
mreq4.imr_interface.s_addr = htonl(firstIP.toIPv4Address());
|
||||
|
|
|
|||
|
|
@ -936,7 +936,7 @@ static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d,
|
|||
mreq4.imr_multiaddr.s_addr = htonl(groupAddress.toIPv4Address());
|
||||
|
||||
if (iface.isValid()) {
|
||||
QList<QNetworkAddressEntry> addressEntries = iface.addressEntries();
|
||||
const QList<QNetworkAddressEntry> addressEntries = iface.addressEntries();
|
||||
if (!addressEntries.isEmpty()) {
|
||||
QHostAddress firstIP = addressEntries.first().ip();
|
||||
mreq4.imr_interface.s_addr = htonl(firstIP.toIPv4Address());
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ QAsn1Element QAsn1Element::fromObjectId(const QByteArray &id)
|
|||
{
|
||||
QAsn1Element elem;
|
||||
elem.mType = ObjectIdentifierType;
|
||||
QList<QByteArray> bits = id.split('.');
|
||||
const QList<QByteArray> bits = id.split('.');
|
||||
Q_ASSERT(bits.size() > 2);
|
||||
elem.mValue += quint8((bits[0].toUInt() * 40 + bits[1].toUInt()));
|
||||
for (int i = 2; i < bits.size(); ++i) {
|
||||
|
|
@ -311,11 +311,11 @@ QByteArray QAsn1Element::toObjectId() const
|
|||
{
|
||||
QByteArray key;
|
||||
if (mType == ObjectIdentifierType && !mValue.isEmpty()) {
|
||||
quint8 b = mValue[0];
|
||||
quint8 b = mValue.at(0);
|
||||
key += QByteArray::number(b / 40) + '.' + QByteArray::number (b % 40);
|
||||
unsigned int val = 0;
|
||||
for (int i = 1; i < mValue.size(); ++i) {
|
||||
b = mValue[i];
|
||||
b = mValue.at(i);
|
||||
val = (val << 7) | (b & 0x7f);
|
||||
if (!(b & 0x80)) {
|
||||
key += '.' + QByteArray::number(val);
|
||||
|
|
|
|||
|
|
@ -507,7 +507,7 @@ QString QSslCertificate::toText() const
|
|||
void QSslCertificatePrivate::init(const QByteArray &data, QSsl::EncodingFormat format)
|
||||
{
|
||||
if (!data.isEmpty()) {
|
||||
QList<QSslCertificate> certs = (format == QSsl::Pem)
|
||||
const QList<QSslCertificate> certs = (format == QSsl::Pem)
|
||||
? certificatesFromPem(data, 1)
|
||||
: certificatesFromDer(data, 1);
|
||||
if (!certs.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ QString QSslCertificate::toText() const
|
|||
void QSslCertificatePrivate::init(const QByteArray &data, QSsl::EncodingFormat format)
|
||||
{
|
||||
if (!data.isEmpty()) {
|
||||
QList<QSslCertificate> certs = (format == QSsl::Pem)
|
||||
const QList<QSslCertificate> certs = (format == QSsl::Pem)
|
||||
? certificatesFromPem(data, 1)
|
||||
: certificatesFromDer(data, 1);
|
||||
if (!certs.isEmpty()) {
|
||||
|
|
@ -309,7 +309,7 @@ bool QSslCertificatePrivate::parse(const QByteArray &data)
|
|||
if (!elem.read(versionStream) || elem.type() != QAsn1Element::IntegerType)
|
||||
return false;
|
||||
|
||||
versionString = QByteArray::number(elem.value()[0] + 1);
|
||||
versionString = QByteArray::number(elem.value().at(0) + 1);
|
||||
if (!elem.read(certStream))
|
||||
return false;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ void QSslKeyPrivate::decodeDer(const QByteArray &der, bool deepClear)
|
|||
QDataStream keyStream(elem.value());
|
||||
if (!elem.read(keyStream) || elem.type() != QAsn1Element::SequenceType)
|
||||
return;
|
||||
QVector<QAsn1Element> infoItems = elem.toVector();
|
||||
const QVector<QAsn1Element> infoItems = elem.toVector();
|
||||
if (infoItems.size() < 2 || infoItems[0].type() != QAsn1Element::ObjectIdentifierType)
|
||||
return;
|
||||
if (algorithm == QSsl::Rsa) {
|
||||
|
|
@ -189,7 +189,7 @@ void QSslKeyPrivate::decodeDer(const QByteArray &der, bool deepClear)
|
|||
if (infoItems[1].type() != QAsn1Element::SequenceType)
|
||||
return;
|
||||
// key params
|
||||
QVector<QAsn1Element> params = infoItems[1].toVector();
|
||||
const QVector<QAsn1Element> params = infoItems[1].toVector();
|
||||
if (params.isEmpty() || params[0].type() != QAsn1Element::IntegerType)
|
||||
return;
|
||||
keyLength = numberOfBits(params[0].value());
|
||||
|
|
@ -202,7 +202,7 @@ void QSslKeyPrivate::decodeDer(const QByteArray &der, bool deepClear)
|
|||
}
|
||||
|
||||
} else {
|
||||
QVector<QAsn1Element> items = elem.toVector();
|
||||
const QVector<QAsn1Element> items = elem.toVector();
|
||||
if (items.isEmpty())
|
||||
return;
|
||||
|
||||
|
|
@ -249,7 +249,7 @@ void QSslKeyPrivate::decodePem(const QByteArray &pem, const QByteArray &passPhra
|
|||
QMap<QByteArray, QByteArray> headers;
|
||||
QByteArray data = derFromPem(pem, &headers);
|
||||
if (headers.value("Proc-Type") == "4,ENCRYPTED") {
|
||||
QList<QByteArray> dekInfo = headers.value("DEK-Info").split(',');
|
||||
const QList<QByteArray> dekInfo = headers.value("DEK-Info").split(',');
|
||||
if (dekInfo.size() != 2) {
|
||||
clear(deepClear);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -2526,7 +2526,7 @@ void QSslSocketPrivate::_q_resumeImplementation()
|
|||
if (verifyErrorsHaveBeenIgnored()) {
|
||||
continueHandshake();
|
||||
} else {
|
||||
setErrorAndEmit(QAbstractSocket::SslHandshakeFailedError, sslErrors.first().errorString());
|
||||
setErrorAndEmit(QAbstractSocket::SslHandshakeFailedError, sslErrors.constFirst().errorString());
|
||||
plainSocket->disconnectFromHost();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -442,7 +442,7 @@ void QSslSocketPrivate::ensureInitialized()
|
|||
SSLGetSupportedCiphers(context, cfCiphers.data(), &numCiphers);
|
||||
|
||||
for (size_t i = 0; i < size_t(cfCiphers.size()); ++i) {
|
||||
const QSslCipher ciph(QSslSocketBackendPrivate::QSslCipher_from_SSLCipherSuite(cfCiphers[i]));
|
||||
const QSslCipher ciph(QSslSocketBackendPrivate::QSslCipher_from_SSLCipherSuite(cfCiphers.at(i)));
|
||||
if (!ciph.isNull()) {
|
||||
ciphers << ciph;
|
||||
if (ciph.usedBits() >= 128)
|
||||
|
|
@ -1033,7 +1033,7 @@ bool QSslSocketBackendPrivate::setSessionCertificate(QString &errorDescription,
|
|||
|
||||
QSslCertificate localCertificate;
|
||||
if (!configuration.localCertificateChain.isEmpty())
|
||||
localCertificate = configuration.localCertificateChain[0];
|
||||
localCertificate = configuration.localCertificateChain.at(0);
|
||||
|
||||
if (!localCertificate.isNull()) {
|
||||
// Require a private key as well.
|
||||
|
|
@ -1327,7 +1327,7 @@ bool QSslSocketBackendPrivate::checkSslErrors()
|
|||
paused = true;
|
||||
} else {
|
||||
setErrorAndEmit(QAbstractSocket::SslHandshakeFailedError,
|
||||
sslErrors.first().errorString());
|
||||
sslErrors.constFirst().errorString());
|
||||
plainSocket->disconnectFromHost();
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1234,7 +1234,7 @@ bool QSslSocketBackendPrivate::checkSslErrors()
|
|||
pauseSocketNotifiers(q);
|
||||
paused = true;
|
||||
} else {
|
||||
setErrorAndEmit(QAbstractSocket::SslHandshakeFailedError, sslErrors.first().errorString());
|
||||
setErrorAndEmit(QAbstractSocket::SslHandshakeFailedError, sslErrors.constFirst().errorString());
|
||||
plainSocket->disconnectFromHost();
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -626,7 +626,7 @@ HRESULT QSslSocketBackendPrivate::onSslUpgrade(IAsyncAction *action, AsyncStatus
|
|||
|
||||
if (!sslErrors.isEmpty()) {
|
||||
emit q->sslErrors(sslErrors);
|
||||
setErrorAndEmit(QAbstractSocket::SslHandshakeFailedError, sslErrors.first().errorString());
|
||||
setErrorAndEmit(QAbstractSocket::SslHandshakeFailedError, sslErrors.constFirst().errorString());
|
||||
|
||||
// Disconnect if there are any non-ignorable errors
|
||||
for (const QSslError &error : qAsConst(sslErrors)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue