HTTPClientSession* HTTPSSessionInstantiator::createClientSession(const Poco::URI& uri)
{
	poco_assert (uri.getScheme() == "https");
	HTTPSClientSession* pSession = _pContext.isNull() ? new HTTPSClientSession(uri.getHost(), uri.getPort()) : new HTTPSClientSession(uri.getHost(), uri.getPort(), _pContext);
	if (!proxyHost().empty())
	{
		pSession->setProxy(proxyHost(), proxyPort());
		pSession->setProxyCredentials(proxyUsername(), proxyPassword());
	}
	return pSession;
}
Пример #2
0
static void setupNetwork(GlobalSettings *settings)
{
    QNetworkProxy proxy;
    if (settings->isEnabled(GlobalSettings::Proxy)) {
        QString proxyHost(settings->value(GlobalSettings::ProxyHost).toString());
        int proxyPort = settings->value(GlobalSettings::ProxyPort).toInt();
        proxy.setType(QNetworkProxy::HttpProxy);
        proxy.setHostName(proxyHost);
        proxy.setPort(proxyPort);
        QNetworkProxy::setApplicationProxy(proxy);
        qWarning() << "Using proxy host" << proxyHost << "on port" << proxyPort;
    }

    // Set Internet Access Point
    QNetworkConfigurationManager mgr;
    QList<QNetworkConfiguration> activeConfigs = mgr.allConfigurations();
    if (activeConfigs.count() <= 0)
        return;

    QNetworkConfiguration cfg = activeConfigs.at(0);
    foreach(QNetworkConfiguration config, activeConfigs) {
        if (config.type() == QNetworkConfiguration::UserChoice) {
            cfg = config;
            break;
        }
    }

    g_networkSession = new QNetworkSession(cfg);
    g_networkSession->open();
    g_networkSession->waitForOpened(-1);
}
Пример #3
0
/*!
  \brief Determines if something has changed.

  We do that by comparing every value against what is stored in the storage.

  \return \arg \c true  Yes, something has changed.
          \arg \c false No, nothing changed.
*/
bool
Settings::changed() const
{
  if( apiKey() != Storage::loadString( QL( "apiKey" ) ) )
    return true;

  if( useSystemProxy() != Storage::loadBool( QL( "useSystemProxy" ) ) )
    return true;

  if( useSystemProxy() )
    return false;

  if( proxyHost() != Storage::loadString( QL( "proxyHost" ) ) )
    return true;

  if( proxyPort() != Storage::loadUShort( QL( "proxyPort" ) ) )
    return true;

  if( proxyLogin() != Storage::loadString( QL( "proxyLogin" ) ) )
    return true;

  if( proxyPassword() != Storage::loadString( QL( "proxyPassword" ) ) )
    return true;

  return false;
}
HTTPClientSession* HTTPSSessionInstantiator::createClientSession(const Poco::URI& uri)
{
	poco_assert (uri.getScheme() == "https");
	HTTPSClientSession* pSession = new HTTPSClientSession(uri.getHost(), uri.getPort());
	pSession->setProxy(proxyHost(), proxyPort());
	return pSession;
}
Пример #5
0
Settings::Settings()
 : m_settingsMain( new QSettings(QSettings::IniFormat, QSettings::UserScope, "KDE", "Installer") )

{
    m_settings = new QSettings(installDir()+"/etc/installer.ini",QSettings::IniFormat);
    QString version = m_settings->value("version", "").toString();
    // update to current version
    if (version.isEmpty()) // version 1
    {
        m_settings->setValue("version", SETTINGS_VERSION);
        setPackageManagerMode(m_settings->value("DeveloperMode",false).toBool());
        m_settings->remove("DeveloperMode");
        m_settings->sync();
    }
    else if (version != SETTINGS_VERSION)
    {
        qCritical() << "unknown settings version" << version << "found"; 
    }

#ifdef DEBUG
    qDebug() << "installDir:" << installDir();
    qDebug() << "downloadDir:" << downloadDir();
    qDebug() << "showTitlePage:" << showTitlePage();
    qDebug() << "createStartMenuEntries:" << createStartMenuEntries();
    qDebug() << "isFirstRun" << isFirstRun();
    qDebug() << "proxyMode" << proxyMode();
    qDebug() << "proxyHost" << proxyHost();
    qDebug() << "proxyPort" << proxyPort();
#endif
#ifndef Q_OS_WIN
//     setProxyMode(Environment);
#endif
}
Пример #6
0
void HTTPTransportTest::testSetProperty()
{
    HTTPTransport transport;
    transport.setProperty("foo", "bar");
    QString proxyHost("http://foo.bar.net");
    transport.setProperty(HTTPNUMBEROFRESENDATTEMPTSPROP, "10");
    transport.setProperty(HTTPPROXYHOSTPROP, proxyHost);
    transport.setProperty(HTTPPROXYPORTPROP, "5555");

    QNetworkProxy proxy = transport.getProxyConfig();
    QCOMPARE(proxy.hostName(), proxyHost);
    QCOMPARE(proxy.port(), (quint16)5555);
}
Пример #7
0
void HTTPTransportTest::testSetProxy()
{
    HTTPTransport transport;
    QNetworkProxy proxy;
    QString proxyHost("http://foo.bar.net");
    quint16 port = 5555;
    proxy.setHostName(proxyHost);
    proxy.setPort(port);
    transport.setProxyConfig(proxy);

    proxy = transport.getProxyConfig();
    QCOMPARE(proxy.hostName(), proxyHost);
    QCOMPARE(proxy.port(), port);
}
Пример #8
0
std::string ZLCurlNetworkManager::perform(const ZLExecutionData::Vector &dataList) const {
	const ZLResource &errorResource = ZLResource::resource("dialog")["networkError"];

	if (dataList.empty()) {
		return errorResource["emptyLibrariesList"].value();
	}

	std::set<std::string> errors;

	const std::string proxy = proxyHost() + ':' + proxyPort();
	CURLM *handle = curl_multi_init();

	std::map<CURL*,shared_ptr<ZLExecutionData> > handleToRequest;

	for (ZLExecutionData::Vector::const_iterator it = dataList.begin(); it != dataList.end(); ++it) {
		if (it->isNull() || !(*it)->isInstanceOf(ZLNetworkRequest::TYPE_ID)) {
			continue;
		}
		ZLNetworkRequest &request = (ZLNetworkRequest&)**it;
		const std::string err = doBeforeRequest(request);
		if (!err.empty()) {
			errors.insert(err);
			continue;
		}
		CURL *easyHandle = curl_easy_init();
		if (easyHandle != 0) {
			handleToRequest[easyHandle] = *it;
			setStandardOptions(easyHandle, proxy);
			setRequestOptions(easyHandle, request);
			curl_multi_add_handle(handle, easyHandle);
		}
	}

	int counter;
	CURLMcode res;
	do {
		res = curl_multi_perform(handle, &counter);
	} while ((res == CURLM_CALL_MULTI_PERFORM) || (counter > 0));

	CURLMsg *message;
	do {
		int queueSize;
		message = curl_multi_info_read(handle, &queueSize);
		if ((message != 0) && (message->msg == CURLMSG_DONE)) {
			ZLNetworkRequest &request = (ZLNetworkRequest&)*handleToRequest[message->easy_handle];
			const std::string &url = request.url();

			CURLcode result = message->data.result;
			bool doAfterResult = request.doAfter(result == CURLE_OK);
			if (result == CURLE_OK && !doAfterResult) {
				result = CURLE_WRITE_ERROR;
			}

			switch (result) {
				case CURLE_OK:
					break;
				case CURLE_WRITE_ERROR:
					if (!request.errorMessage().empty()) {
						errors.insert(request.errorMessage());
					} else {
						errors.insert(ZLStringUtil::printf(errorResource["somethingWrongMessage"].value(), ZLNetworkUtil::hostFromUrl(url)));
					}
					break;
				default:
					errors.insert(ZLStringUtil::printf(errorResource["somethingWrongMessage"].value(), ZLNetworkUtil::hostFromUrl(url)));
					break;
				case CURLE_COULDNT_RESOLVE_PROXY:
					errors.insert(ZLStringUtil::printf(errorResource["couldntResolveProxyMessage"].value(), proxyHost()));
					break;
				case CURLE_COULDNT_RESOLVE_HOST:
					errors.insert(ZLStringUtil::printf(errorResource["couldntResolveHostMessage"].value(), ZLNetworkUtil::hostFromUrl(url)));
					break;
				case CURLE_COULDNT_CONNECT:
					errors.insert(ZLStringUtil::printf(errorResource["couldntConnectMessage"].value(), ZLNetworkUtil::hostFromUrl(url)));
					break;
				case CURLE_OPERATION_TIMEDOUT:
					errors.insert(errorResource["operationTimedOutMessage"].value());
					break;
				case CURLE_SSL_CONNECT_ERROR:
					errors.insert(ZLStringUtil::printf(errorResource["sslConnectErrorMessage"].value(), curl_easy_strerror(CURLE_SSL_CONNECT_ERROR)));
					break;
#if LIBCURL_VERSION_NUM > 0x071100
				case CURLE_PEER_FAILED_VERIFICATION:
#else
				case CURLE_SSL_PEER_CERTIFICATE:
#endif
					errors.insert(ZLStringUtil::printf(errorResource["peerFailedVerificationMessage"].value(), ZLNetworkUtil::hostFromUrl(url)));
					break;
				case CURLE_SSL_CACERT:
					errors.insert(ZLStringUtil::printf(errorResource["sslCertificateAuthorityMessage"].value(), ZLNetworkUtil::hostFromUrl(url)));
					break;
				case CURLE_SSL_CACERT_BADFILE:
					errors.insert(ZLStringUtil::printf(errorResource["sslBadCertificateFileMessage"].value(), request.sslCertificate().Path));
					break;
				case CURLE_SSL_SHUTDOWN_FAILED:
					errors.insert(ZLStringUtil::printf(errorResource["sslShutdownFailedMessage"].value(), ZLNetworkUtil::hostFromUrl(url)));
					break;
			}
		}
	} while ((message != 0) && (errors.size() < 3));

	for (std::map<CURL*,shared_ptr<ZLExecutionData> >::const_iterator jt = handleToRequest.begin(); jt != handleToRequest.end(); ++jt) {
		CURL *easyHandle = jt->first;
		curl_multi_remove_handle(handle, easyHandle);
		curl_easy_cleanup(easyHandle);

		ZLNetworkRequest &request = (ZLNetworkRequest&)*jt->second;
		clearRequestOptions(request);
	}
	handleToRequest.clear();
	curl_multi_cleanup(handle);

	std::string result;
	for (std::set<std::string>::const_iterator et = errors.begin(); et != errors.end(); ++et) {
		if (!result.empty()) {
			result += '\n';
		}
		result += *et;
	}
	return result;
}
Пример #9
0
QString Config::proxy() const
{
    return proxyHost() + ":" + proxyPort();
}