本文整理汇总了C++中QNetworkProxyQuery::queryType方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkProxyQuery::queryType方法的具体用法?C++ QNetworkProxyQuery::queryType怎么用?C++ QNetworkProxyQuery::queryType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkProxyQuery
的用法示例。
在下文中一共展示了QNetworkProxyQuery::queryType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: systemProxyForQuery
QList<QNetworkProxy> PackageManagerProxyFactory::queryProxy(const QNetworkProxyQuery &query)
{
const Settings &settings = m_core->settings();
QList<QNetworkProxy> list;
if (settings.proxyType() == Settings::SystemProxy) {
#if defined(Q_OS_UNIX) && !defined(Q_OS_OSX)
QUrl proxyUrl = QUrl::fromUserInput(QString::fromUtf8(qgetenv("http_proxy")));
if (proxyUrl.isValid()) {
return list << QNetworkProxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyUrl.port(),
proxyUrl.userName(), proxyUrl.password());
}
#endif
return QNetworkProxyFactory::systemProxyForQuery(query);
}
if ((settings.proxyType() == Settings::NoProxy))
return list << QNetworkProxy(QNetworkProxy::NoProxy);
if (query.queryType() == QNetworkProxyQuery::UrlRequest) {
if (query.url().scheme() == QLatin1String("ftp"))
return list << settings.ftpProxy();
if ((query.url().scheme() == QLatin1String("http"))
|| (query.url().scheme() == QLatin1String("https"))) {
return list << settings.httpProxy();
}
}
return list << QNetworkProxy(QNetworkProxy::DefaultProxy);
}
示例2: systemProxyForQuery
QList<QNetworkProxy> PackageManagerProxyFactory::queryProxy(const QNetworkProxyQuery &query)
{
const Settings &settings = m_core->settings();
QList<QNetworkProxy> list;
if (settings.proxyType() == Settings::SystemProxy) {
QList<QNetworkProxy> systemProxies = systemProxyForQuery(query);
auto proxyIter = systemProxies.begin();
for (; proxyIter != systemProxies.end(); ++proxyIter) {
QNetworkProxy &proxy = *proxyIter;
auto p = std::find_if(m_proxyCredentials.constBegin(), m_proxyCredentials.constEnd(),
FindProxyCredential(proxy.hostName(), proxy.port()));
if (p != m_proxyCredentials.constEnd()) {
proxy.setUser(p->user);
proxy.setPassword(p->password);
}
}
return systemProxies;
}
if ((settings.proxyType() == Settings::NoProxy))
return list << QNetworkProxy(QNetworkProxy::NoProxy);
if (query.queryType() == QNetworkProxyQuery::UrlRequest) {
QNetworkProxy proxy;
if (query.url().scheme() == QLatin1String("ftp")) {
proxy = settings.ftpProxy();
} else if (query.url().scheme() == QLatin1String("http")
|| query.url().scheme() == QLatin1String("https")) {
proxy = settings.httpProxy();
}
auto p = std::find_if(m_proxyCredentials.constBegin(), m_proxyCredentials.constEnd(),
FindProxyCredential(proxy.hostName(), proxy.port()));
if (p != m_proxyCredentials.constEnd()) {
proxy.setUser(p->user);
proxy.setPassword(p->password);
}
return list << proxy;
}
return list << QNetworkProxy(QNetworkProxy::DefaultProxy);
}
示例3: bUrl
QT_BEGIN_NAMESPACE
QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query)
{
QNetworkProxy proxy;
if (query.queryType() != QNetworkProxyQuery::UrlRequest) {
qWarning("Unsupported query type: %d", query.queryType());
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
QUrl url = query.url();
if (!url.isValid()) {
qWarning("Invalid URL: %s", qPrintable(url.toString()));
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
netstatus_proxy_details_t details;
memset(&details, 0, sizeof(netstatus_proxy_details_t));
#if BPS_VERSION >= 3001001
QByteArray bUrl(url.toEncoded());
QString sInterface(query.networkConfiguration().name());
QByteArray bInterface;
if (!sInterface.isEmpty()) {
if (query.networkConfiguration().type() != QNetworkConfiguration::InternetAccessPoint) {
qWarning("Unsupported configuration type: %d", query.networkConfiguration().type());
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
bInterface = sInterface.toUtf8();
}
if (netstatus_get_proxy_details_for_url(bUrl.constData(), (bInterface.isEmpty() ? NULL : bInterface.constData()), &details) != BPS_SUCCESS) {
qWarning("netstatus_get_proxy_details_for_url failed! errno: %d", errno);
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
#else
if (netstatus_get_proxy_details(&details) != BPS_SUCCESS) {
qWarning("netstatus_get_proxy_details failed! errno: %d", errno);
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
#endif
if (details.http_proxy_host == NULL) { // No proxy
netstatus_free_proxy_details(&details);
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
QString protocol = query.protocolTag();
if (protocol.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) { // http, https
proxy.setType((QNetworkProxy::HttpProxy));
} else if (protocol == QLatin1String("ftp")) {
proxy.setType(QNetworkProxy::FtpCachingProxy);
} else { // assume http proxy
qDebug("Proxy type: %s assumed to be http proxy", qPrintable(protocol));
proxy.setType((QNetworkProxy::HttpProxy));
}
// Set host
// Note: ftp and https proxy type fields *are* obsolete.
// The user interface allows only one host/port which gets duplicated
// to all proxy type fields.
proxy.setHostName(QString::fromUtf8(details.http_proxy_host));
// Set port
proxy.setPort(details.http_proxy_port);
// Set username
if (details.http_proxy_login_user)
proxy.setUser(QString::fromUtf8(details.http_proxy_login_user));
// Set password
if (details.http_proxy_login_password)
proxy.setPassword(QString::fromUtf8(details.http_proxy_login_password));
netstatus_free_proxy_details(&details);
return QList<QNetworkProxy>() << proxy;
}