Using proper virtual functions instead of Q_INVOKABLE tricks.

This mantains BC between version compiled with and without OPENSSL,
which was the reason for the use of "runtime virtuals". Using proper
virtuals should make code clearer.

Change-Id: I24f141ebaab68c000c2d602b54addbae1679a424
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Jonas M. Gastal 2011-12-22 13:53:38 -02:00 committed by Qt by Nokia
parent 4669d657d2
commit 159098719b
6 changed files with 68 additions and 47 deletions

View File

@ -586,13 +586,7 @@ QVariant QNetworkReply::attribute(QNetworkRequest::Attribute code) const
QSslConfiguration QNetworkReply::sslConfiguration() const
{
QSslConfiguration config;
// determine if we support this extension
int id = metaObject()->indexOfMethod("sslConfigurationImplementation()");
if (id != -1) {
void *arr[] = { &config, 0 };
const_cast<QNetworkReply *>(this)->qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
}
sslConfigurationImplementation(config);
return config;
}
@ -602,15 +596,7 @@ QSslConfiguration QNetworkReply::sslConfiguration() const
*/
void QNetworkReply::setSslConfiguration(const QSslConfiguration &config)
{
if (config.isNull())
return;
int id = metaObject()->indexOfMethod("setSslConfigurationImplementation(QSslConfiguration)");
if (id != -1) {
QSslConfiguration copy(config);
void *arr[] = { 0, &copy };
qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
}
setSslConfigurationImplementation(config);
}
/*!
@ -635,17 +621,52 @@ void QNetworkReply::setSslConfiguration(const QSslConfiguration &config)
*/
void QNetworkReply::ignoreSslErrors(const QList<QSslError> &errors)
{
// do this cryptic trick, because we could not add a virtual method to this class later on
// since that breaks binary compatibility
int id = metaObject()->indexOfMethod("ignoreSslErrorsImplementation(QList<QSslError>)");
if (id != -1) {
QList<QSslError> copy(errors);
void *arr[] = { 0, &copy };
qt_metacall(QMetaObject::InvokeMetaMethod, id, arr);
}
ignoreSslErrorsImplementation(errors);
}
#endif
/*!
\fn void QNetworkReply::sslConfigurationImplementation(QSslConfiguration &configuration) const
\since 5.0
This virtual method is provided to enable overriding the behavior of
sslConfiguration(). sslConfiguration() is a public wrapper for this method.
The configuration will be returned in \a configuration.
\sa sslConfiguration()
*/
void QNetworkReply::sslConfigurationImplementation(QSslConfiguration &) const
{
}
/*!
\fn void QNetworkReply::setSslConfigurationImplementation(const QSslConfiguration &configuration)
\since 5.0
This virtual method is provided to enable overriding the behavior of
setSslConfiguration(). setSslConfiguration() is a public wrapper for this method.
If you override this method use \a configuration to set the SSL configuration.
\sa sslConfigurationImplementation(), setSslConfiguration()
*/
void QNetworkReply::setSslConfigurationImplementation(const QSslConfiguration &)
{
}
/*!
\fn void QNetworkReply::ignoreSslErrorsImplementation(const QList<QSslError> &errors)
\since 5.0
This virtual method is provided to enable overriding the behavior of
ignoreSslErrors(). ignoreSslErrors() is a public wrapper for this method.
\a errors contains the errors the user wishes ignored.
\sa ignoreSslErrors()
*/
void QNetworkReply::ignoreSslErrorsImplementation(const QList<QSslError> &)
{
}
/*!
If this function is called, SSL errors related to network
connection will be ignored, including certificate validation

View File

@ -169,6 +169,10 @@ protected:
void setRawHeader(const QByteArray &headerName, const QByteArray &value);
void setAttribute(QNetworkRequest::Attribute code, const QVariant &value);
virtual void sslConfigurationImplementation(QSslConfiguration &) const;
virtual void setSslConfigurationImplementation(const QSslConfiguration &);
virtual void ignoreSslErrorsImplementation(const QList<QSslError> &);
private:
Q_DECLARE_PRIVATE(QNetworkReply)
};

View File

@ -410,10 +410,10 @@ void QNetworkReplyHttpImpl::setSslConfigurationImplementation(const QSslConfigur
Q_UNUSED(newconfig);
}
QSslConfiguration QNetworkReplyHttpImpl::sslConfigurationImplementation() const
void QNetworkReplyHttpImpl::sslConfigurationImplementation(QSslConfiguration &configuration) const
{
Q_D(const QNetworkReplyHttpImpl);
return d->sslConfiguration;
configuration = d->sslConfiguration;
}
#endif

View File

@ -94,16 +94,6 @@ public:
void setReadBufferSize(qint64 size);
bool canReadLine () const;
#ifndef QT_NO_OPENSSL
void ignoreSslErrors();
// ### Qt5 Add proper virtual
Q_INVOKABLE void ignoreSslErrorsImplementation(const QList<QSslError> &errors);
// ### Qt5 Add proper virtual
Q_INVOKABLE void setSslConfigurationImplementation(const QSslConfiguration &configuration);
// ### Qt5 Add proper virtual
Q_INVOKABLE QSslConfiguration sslConfigurationImplementation() const;
#endif
Q_DECLARE_PRIVATE(QNetworkReplyHttpImpl)
Q_PRIVATE_SLOT(d_func(), void _q_startOperation())
Q_PRIVATE_SLOT(d_func(), void _q_cacheLoadReadyRead())
@ -135,6 +125,13 @@ public:
Q_PRIVATE_SLOT(d_func(), void emitReplyUploadProgress(qint64, qint64))
#ifndef QT_NO_OPENSSL
protected:
void ignoreSslErrors();
void ignoreSslErrorsImplementation(const QList<QSslError> &errors);
void setSslConfigurationImplementation(const QSslConfiguration &configuration);
void sslConfigurationImplementation(QSslConfiguration &configuration) const;
#endif
signals:
// To HTTP thread:

View File

@ -930,13 +930,11 @@ void QNetworkReplyImpl::setReadBufferSize(qint64 size)
}
#ifndef QT_NO_OPENSSL
QSslConfiguration QNetworkReplyImpl::sslConfigurationImplementation() const
void QNetworkReplyImpl::sslConfigurationImplementation(QSslConfiguration &configuration) const
{
Q_D(const QNetworkReplyImpl);
QSslConfiguration config;
if (d->backend)
d->backend->fetchSslConfiguration(config);
return config;
d->backend->fetchSslConfiguration(configuration);
}
void QNetworkReplyImpl::setSslConfigurationImplementation(const QSslConfiguration &config)

View File

@ -87,13 +87,6 @@ public:
virtual qint64 readData(char *data, qint64 maxlen);
virtual bool event(QEvent *);
#ifndef QT_NO_OPENSSL
Q_INVOKABLE QSslConfiguration sslConfigurationImplementation() const;
Q_INVOKABLE void setSslConfigurationImplementation(const QSslConfiguration &configuration);
virtual void ignoreSslErrors();
Q_INVOKABLE virtual void ignoreSslErrorsImplementation(const QList<QSslError> &errors);
#endif
Q_DECLARE_PRIVATE(QNetworkReplyImpl)
Q_PRIVATE_SLOT(d_func(), void _q_startOperation())
Q_PRIVATE_SLOT(d_func(), void _q_copyReadyRead())
@ -104,6 +97,14 @@ public:
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionConnected())
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed())
#endif
#ifndef QT_NO_OPENSSL
protected:
void sslConfigurationImplementation(QSslConfiguration &configuration) const;
void setSslConfigurationImplementation(const QSslConfiguration &configuration);
virtual void ignoreSslErrors();
virtual void ignoreSslErrorsImplementation(const QList<QSslError> &errors);
#endif
};
class QNetworkReplyImplPrivate: public QNetworkReplyPrivate