本文整理汇总了C++中QNetworkProxyQuery::peerHostName方法的典型用法代码示例。如果您正苦于以下问题:C++ QNetworkProxyQuery::peerHostName方法的具体用法?C++ QNetworkProxyQuery::peerHostName怎么用?C++ QNetworkProxyQuery::peerHostName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QNetworkProxyQuery
的用法示例。
在下文中一共展示了QNetworkProxyQuery::peerHostName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: systemProxyForQuery
virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery& query = QNetworkProxyQuery())
{
if ((query.peerHostName().compare("localhost", Qt::CaseInsensitive) == 0) ||
(query.peerHostName().compare("127.0.0.1") == 0))
{
return *_defaultProxyList;
} else if (_useProxy) {
return *_proxyList;
} else {
return QNetworkProxyFactory::systemProxyForQuery(query);
}
}
示例2: systemProxyForQuery
QList<QNetworkProxy> NetworkProxyFactory::queryProxy(const QNetworkProxyQuery& query)
{
QList<QNetworkProxy> results;
if (query.peerHostName() == QString::fromAscii("127.0.0.1")
|| query.peerHostName().toLower() == QString::fromAscii("localhost"))
{
results.append(QNetworkProxy::NoProxy);
}
else
{
results = systemProxyForQuery(query);
}
return results;
}
示例3:
QList<QNetworkProxy> EnvHttpProxyFactory::queryProxy(const QNetworkProxyQuery& query)
{
QString protocol = query.protocolTag().toLower();
bool localHost = false;
if (!query.peerHostName().compare(QLatin1String("localhost"), Qt::CaseInsensitive) || !query.peerHostName().compare(QLatin1String("127.0.0.1"), Qt::CaseInsensitive))
localHost = true;
if (protocol == QLatin1String("http") && !localHost)
return m_httpProxy;
if (protocol == QLatin1String("https") && !localHost)
return m_httpsProxy;
QList<QNetworkProxy> proxies;
proxies << QNetworkProxy::NoProxy;
return proxies;
}
示例4: if
QList< QNetworkProxy >
NetworkProxyFactory::queryProxy( const QNetworkProxyQuery& query )
{
//tDebug() << Q_FUNC_INFO << "query hostname is " << query.peerHostName();
QList< QNetworkProxy > proxies;
QString hostname = query.peerHostName();
s_noProxyHostsMutex.lock();
if ( s_noProxyHosts.contains( hostname ) )
proxies << QNetworkProxy::NoProxy << systemProxyForQuery( query );
else if ( m_proxy.hostName().isEmpty() || hostname.isEmpty() || TomahawkSettings::instance()->proxyType() == QNetworkProxy::NoProxy )
proxies << systemProxyForQuery( query );
else
proxies << m_proxy << systemProxyForQuery( query );
s_noProxyHostsMutex.unlock();
return proxies;
}
示例5: systemProxyForQuery
QList<QNetworkProxy> NetworkProxyFactory::queryProxy(const QNetworkProxyQuery &query)
{
if (m_proxyMode == SystemProxy)
{
return QNetworkProxyFactory::systemProxyForQuery(query);
}
if (m_proxyMode == ManualProxy)
{
const QString protocol = query.protocolTag().toLower();
if (m_proxies.contains(QNetworkProxy::Socks5Proxy))
{
return m_proxies[QNetworkProxy::Socks5Proxy];
}
else if (protocol == QLatin1String("http") && m_proxies.contains(QNetworkProxy::HttpProxy))
{
return m_proxies[QNetworkProxy::HttpProxy];
}
else if (protocol == QLatin1String("https") && m_proxies.contains(QNetworkProxy::HttpCachingProxy))
{
return m_proxies[QNetworkProxy::HttpCachingProxy];
}
else if (protocol == QLatin1String("ftp") && m_proxies.contains(QNetworkProxy::FtpCachingProxy))
{
return m_proxies[QNetworkProxy::FtpCachingProxy];
}
else
{
return m_proxies[QNetworkProxy::NoProxy];
}
}
if (m_proxyMode == AutomaticProxy && m_automaticProxy)
{
return m_automaticProxy->getProxy(query.url().toString(), query.peerHostName());
}
return m_proxies[QNetworkProxy::NoProxy];
}
示例6: bUrl
QT_BEGIN_NAMESPACE
QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query)
{
if (query.url().scheme() == QLatin1String("file")
|| query.url().scheme() == QLatin1String("qrc"))
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
if (query.queryType() != QNetworkProxyQuery::UrlRequest
&& query.queryType() != QNetworkProxyQuery::TcpSocket) {
qWarning("Unsupported query type: %d", query.queryType());
return QList<QNetworkProxy>() << QNetworkProxy(QNetworkProxy::NoProxy);
}
QUrl url;
if (query.queryType() == QNetworkProxyQuery::UrlRequest) {
url = query.url();
} else if (query.queryType() == QNetworkProxyQuery::TcpSocket
&& !query.peerHostName().isEmpty()) {
url.setHost(query.peerHostName());
switch (query.peerPort()) {
case 443:
url.setScheme(QLatin1String("https"));
break;
case 21:
url.setScheme(QLatin1String("ftp"));
break;
default:
// for unknown ports, we just pretend we are dealing
// with a HTTP URL, otherwise we will not get a proxy
// from the netstatus API
url.setScheme(QLatin1String("http"));
}
}
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);
}
QNetworkProxy proxy;
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));
//.........这里部分代码省略.........
示例7: macQueryInternal
QList<QNetworkProxy> macQueryInternal(const QNetworkProxyQuery &query)
{
QList<QNetworkProxy> result;
// obtain a dictionary to the proxy settings:
CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL);
if (!dict) {
qWarning("QNetworkProxyFactory::systemProxyForQuery: SCDynamicStoreCopyProxies returned NULL");
return result; // failed
}
if (isHostExcluded(dict, query.peerHostName())) {
CFRelease(dict);
return result; // no proxy for this host
}
// is there a PAC enabled? If so, use it first.
CFNumberRef pacEnabled;
if ((pacEnabled = (CFNumberRef)CFDictionaryGetValue(dict, kSCPropNetProxiesProxyAutoConfigEnable))) {
int enabled;
if (CFNumberGetValue(pacEnabled, kCFNumberIntType, &enabled) && enabled) {
// PAC is enabled
CFStringRef cfPacLocation = (CFStringRef)CFDictionaryGetValue(dict, kSCPropNetProxiesProxyAutoConfigURLString);
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
QCFType<CFDataRef> pacData;
QCFType<CFURLRef> pacUrl = CFURLCreateWithString(kCFAllocatorDefault, cfPacLocation, NULL);
SInt32 errorCode;
if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, pacUrl, &pacData, NULL, NULL, &errorCode)) {
QString pacLocation = QCFString::toQString(cfPacLocation);
qWarning("Unable to get the PAC script at \"%s\" (%s)", qPrintable(pacLocation), cfurlErrorDescription(errorCode));
return result;
}
QCFType<CFStringRef> pacScript = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, pacData, kCFStringEncodingISOLatin1);
if (!pacScript) {
// This should never happen, but the documentation says it may return NULL if there was a problem creating the object.
QString pacLocation = QCFString::toQString(cfPacLocation);
qWarning("Unable to read the PAC script at \"%s\"", qPrintable(pacLocation));
return result;
}
QByteArray encodedURL = query.url().toEncoded(); // converted to UTF-8
if (encodedURL.isEmpty()) {
return result; // Invalid URL, abort
}
QCFType<CFURLRef> targetURL = CFURLCreateWithBytes(kCFAllocatorDefault, (UInt8*)encodedURL.data(), encodedURL.size(), kCFStringEncodingUTF8, NULL);
if (!targetURL) {
return result; // URL creation problem, abort
}
QCFType<CFErrorRef> pacError;
QCFType<CFArrayRef> proxies = CFNetworkCopyProxiesForAutoConfigurationScript(pacScript, targetURL, &pacError);
if (!proxies) {
QString pacLocation = QCFString::toQString(cfPacLocation);
QCFType<CFStringRef> pacErrorDescription = CFErrorCopyDescription(pacError);
qWarning("Execution of PAC script at \"%s\" failed: %s", qPrintable(pacLocation), qPrintable(QCFString::toQString(pacErrorDescription)));
return result;
}
CFIndex size = CFArrayGetCount(proxies);
for (CFIndex i = 0; i < size; ++i) {
CFDictionaryRef proxy = (CFDictionaryRef)CFArrayGetValueAtIndex(proxies, i);
result << proxyFromDictionary(proxy);
}
return result;
} else
#endif
{
QString pacLocation = QCFString::toQString(cfPacLocation);
qWarning("Mac system proxy: PAC script at \"%s\" not handled", qPrintable(pacLocation));
}
}
}
// no PAC, decide which proxy we're looking for based on the query
bool isHttps = false;
QString protocol = query.protocolTag().toLower();
// try the protocol-specific proxy
QNetworkProxy protocolSpecificProxy;
if (protocol == QLatin1String("ftp")) {
protocolSpecificProxy =
proxyFromDictionary(dict, QNetworkProxy::FtpCachingProxy,
kSCPropNetProxiesFTPEnable,
kSCPropNetProxiesFTPProxy,
kSCPropNetProxiesFTPPort);
} else if (protocol == QLatin1String("http")) {
protocolSpecificProxy =
proxyFromDictionary(dict, QNetworkProxy::HttpProxy,
kSCPropNetProxiesHTTPEnable,
kSCPropNetProxiesHTTPProxy,
kSCPropNetProxiesHTTPPort);
} else if (protocol == QLatin1String("https")) {
isHttps = true;
protocolSpecificProxy =
proxyFromDictionary(dict, QNetworkProxy::HttpProxy,
kSCPropNetProxiesHTTPSEnable,
//.........这里部分代码省略.........