Ejemplo n.º 1
0
void SBI_NetworkIcon::showMenu(const QPoint &pos)
{
    QFont boldFont = font();
    boldFont.setBold(true);

    QMenu menu;
    menu.addAction(QIcon::fromTheme("preferences-system-network", QIcon(":sbi/data/preferences-network.png")), tr("Proxy configuration"))->setFont(boldFont);

    QMenu* proxyMenu = menu.addMenu(tr("Select proxy"));

    const QHash<QString, SBI_NetworkProxy*> &proxies = SBINetManager->proxies();

    QHashIterator<QString, SBI_NetworkProxy*> it(proxies);
    while (it.hasNext()) {
        it.next();
        QAction* act = proxyMenu->addAction(it.key(), this, SLOT(useProxy()));
        act->setData(it.key());
        act->setCheckable(true);
        act->setChecked(it.value() == SBINetManager->currentProxy());
    }

    if (proxyMenu->actions().count() == 0) {
        proxyMenu->addAction(tr("Empty"))->setEnabled(false);
    }

    menu.addSeparator();
    menu.addAction(tr("Manage proxies"), this, SLOT(showDialog()));
    menu.exec(pos);
}
Ejemplo n.º 2
0
void LLURLRequest::initialize_impl(void)
{
	// If the header is "Pragma" with no value, the caller intends to
	// force libcurl to drop the Pragma header it so gratuitously inserts.
	// Before inserting the header, force libcurl to not use the proxy.
	std::string pragma_value;
	if (mHeaders.getValue("Pragma", pragma_value) && pragma_value.empty())
	{
		useProxy(false);
	}

	if (mAction == LLHTTPClient::HTTP_PUT || mAction == LLHTTPClient::HTTP_POST)
	{
		// If the Content-Type header was passed in we defer to the caller's wisdom,
		// but if they did not specify a Content-Type, then ask the injector.
		mHeaders.addHeader("Content-Type", mBody->contentType(), AIHTTPHeaders::keep_existing_header);
	}
	else if (mAction != LLHTTPClient::HTTP_HEAD)
	{
		// Check to see if we have already set Accept or not. If no one
		// set it, set it to application/llsd+xml since that's what we
		// almost always want.
		mHeaders.addHeader("Accept", "application/llsd+xml", AIHTTPHeaders::keep_existing_header);
	}

	if (mAction == LLHTTPClient::HTTP_POST && gMessageSystem)
	{
		mHeaders.addHeader("X-SecondLife-UDP-Listen-Port", llformat("%d", gMessageSystem->mPort));
	}

	bool success = false;
	try
	{
		AICurlEasyRequest_wat easy_request_w(*mCurlEasyRequest);
		easy_request_w->prepRequest(easy_request_w, mHeaders, mResponder);

		if (mBody)
		{
			// This might throw AICurlNoBody.
			mBodySize = mBody->get_body(easy_request_w->sChannels, easy_request_w->getInput());
		}

		success = configure(easy_request_w);
	}
	catch (AICurlNoBody const& error)
	{
		llwarns << "Injector::get_body() failed: " << error.what() << llendl; 
	}

	if (success)
	{
		// Continue to initialize base class.
		AICurlEasyRequestStateMachine::initialize_impl();
	}
	else
	{
		abort();
	}
}
Ejemplo n.º 3
0
void ZLCurlNetworkManager::setStandardOptions(CURL *handle, const std::string &proxy) const {
	static const std::string AGENT_NAME = std::string("FBReader/") + VERSION;

	curl_easy_setopt(handle, CURLOPT_USERAGENT, AGENT_NAME.c_str());
	if (useProxy()) {
		curl_easy_setopt(handle, CURLOPT_PROXY, proxy.c_str());
	}
	curl_easy_setopt(handle, CURLOPT_LOW_SPEED_LIMIT, 1L);
	curl_easy_setopt(handle, CURLOPT_LOW_SPEED_TIME, TimeoutOption().value());
	curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, ConnectTimeoutOption().value());
	curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 1L);
	curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 2L);

	const std::string cookies = CookiesPath();
	curl_easy_setopt(handle, CURLOPT_COOKIEFILE, cookies.c_str());
	curl_easy_setopt(handle, CURLOPT_COOKIEJAR, cookies.c_str());
}
Ejemplo n.º 4
0
QVariantMap CoreAccount::toVariantMap(bool forcePassword) const
{
    QVariantMap v;
    v["AccountId"] = accountId().toInt(); // can't use AccountId because then comparison fails
    v["AccountName"] = accountName();
    v["Uuid"] = uuid().toString();
    v["Internal"] = isInternal();
    v["User"] = user();
    if (_storePassword || forcePassword)
        v["Password"] = password();
    else
        v["Password"] = QString();
    v["StorePassword"] = storePassword();
    v["HostName"] = hostName();
    v["Port"] = port();
    v["UseSSL"] = useSsl();
    v["UseProxy"] = useProxy();
    v["ProxyType"] = proxyType();
    v["ProxyUser"] = proxyUser();
    v["ProxyPassword"] = proxyPassword();
    v["ProxyHostName"] = proxyHostName();
    v["ProxyPort"] = proxyPort();
    return v;
}
Ejemplo n.º 5
0
QString KProtocolManager::slaveProtocol(const KURL &url, QString &proxy)
{
    if(url.hasSubURL()) // We don't want the suburl's protocol
    {
        KURL::List list = KURL::split(url);
        KURL::List::Iterator it = list.fromLast();
        return slaveProtocol(*it, proxy);
    }

    if(!d)
        d = new KProtocolManagerPrivate;

    if(d->url == url)
    {
        proxy = d->proxy;
        return d->protocol;
    }

    if(useProxy())
    {
        proxy = proxyForURL(url);
        if((proxy != "DIRECT") && (!proxy.isEmpty()))
        {
            bool isRevMatch = false;
            KProtocolManager::ProxyType type = proxyType();
            bool useRevProxy = ((type == ManualProxy) && useReverseProxy());

            QString noProxy;
            // Check no proxy information iff the proxy type is either
            // ManualProxy or EnvVarProxy
            if((type == ManualProxy) || (type == EnvVarProxy))
                noProxy = noProxyFor();

            if(!noProxy.isEmpty())
            {
                QString qhost = url.host().lower();
                const char *host = qhost.latin1();
                QString qno_proxy = noProxy.stripWhiteSpace().lower();
                const char *no_proxy = qno_proxy.latin1();
                isRevMatch = revmatch(host, no_proxy);

                // If no match is found and the request url has a port
                // number, try the combination of "host:port". This allows
                // users to enter host:port in the No-proxy-For list.
                if(!isRevMatch && url.port() > 0)
                {
                    qhost += ':' + QString::number(url.port());
                    host = qhost.latin1();
                    isRevMatch = revmatch(host, no_proxy);
                }

                // If the hostname does not contain a dot, check if
                // <local> is part of noProxy.
                if(!isRevMatch && host && (strchr(host, '.') == NULL))
                    isRevMatch = revmatch("<local>", no_proxy);
            }

            if((!useRevProxy && !isRevMatch) || (useRevProxy && isRevMatch))
            {
                d->url = proxy;
                if(d->url.isValid())
                {
                    // The idea behind slave protocols is not applicable to http
                    // and webdav protocols.
                    QString protocol = url.protocol().lower();
                    if(protocol.startsWith("http") || protocol.startsWith("webdav"))
                        d->protocol = protocol;
                    else
                    {
                        d->protocol = d->url.protocol();
                        kdDebug() << "slaveProtocol: " << d->protocol << endl;
                    }

                    d->url = url;
                    d->proxy = proxy;
                    return d->protocol;
                }
            }
        }
    }

    d->url = url;
    d->proxy = proxy = QString::null;
    d->protocol = url.protocol();
    return d->protocol;
}
Ejemplo n.º 6
0
// -----------------------------------------------------------------------------
// CHttpFilterProxy::SetProxyL
// Function to handle Submit events.
// Set proxy properties (EUseProxy and EProxyAddress) in order to get connected throught
// proxy when a new HTTP session will be in effect.  The Proxy data will be taken from
// the CommDb if a new connection has been used. If a proxy property has already been 
// set by a higher filter or by the client, then those settings are preferred over 
// CommsDB.
// -----------------------------------------------------------------------------
//
void CHttpFilterProxy::SetProxyL(const RHTTPTransaction aTransaction)
{
    THTTPHdrVal isNewConn, proxyAddress;

    // If connection has been disconnected the user could change Access Point, so let's
    // check if a new connection has been used.
    TBool ret = iConnInfo.Property (iStringPool.StringF(HttpFilterCommonStringsExt::EHttpNewConnFlag,
                                   HttpFilterCommonStringsExt::GetTable()), isNewConn);

    if (ret && isNewConn.Type() == THTTPHdrVal::KTIntVal && (isNewConn.Int() == 1))
    {
        iUsage = EFalse;
        // Read proxy info from the CommDB
        ReadProxyInfoL(iStringPool,
                       iUsage,
                       iProxyAddress,
                       iExceptions);
    }
    else
    {
        TBool useProxy( ETrue );
        THTTPHdrVal proxyUsageVal;

	    // Is the property for proxy usage set?
        TBool hasUsageValue = iConnInfo.Property(iStringPool.StringF(HTTP::EProxyUsage,
                            RHTTPSession::GetTable()), proxyUsageVal);
                            
        // If the property is set, is it EUseProxy
        if (hasUsageValue)
        {
        useProxy = ( proxyUsageVal.StrF().Index(RHTTPSession::GetTable()) == HTTP::EUseProxy);
        }

        // Use proxy if the property value is EUseProxy or no property is set.
        if (useProxy || !hasUsageValue)
        {
            THTTPHdrVal proxyAddressVal;
            TBool hasValue = iConnInfo.Property(iStringPool.StringF(HTTP::EProxyAddress,
                                               RHTTPSession::GetTable()), proxyAddressVal);
            if (!hasValue)
            {
                // The proxyAddress has not been set, so Read proxy info from the CommDB
                ReadProxyInfoL(iStringPool,
                               iUsage,
                               iProxyAddress,
                               iExceptions);

            }
            else
            {
                // Now get the proxy address...
                iProxyAddress = proxyAddressVal.StrF().Copy();
                iUsage = ETrue;
            }
        }
//      }
    }

    // We should not use proxy if the uri matches to one of exceptions from the exception list
    // In this case the Origing server will be used

    ExcptionsCompare(aTransaction);
    
    // Respect proxy settings already defined by client or higher HTTP filter
    THTTPHdrVal proxyUsage;  // Check if property present or not present, not the value.
    if ( !iConnInfo.Property(iStringPool.StringF(HTTP::EProxyUsage,
                            RHTTPSession::GetTable()), proxyUsage)) 
   	{ 

		// Set the proxy address and proxy Usage
		proxyAddress = THTTPHdrVal(iProxyAddress);

		iConnInfo.RemoveProperty(iStringPool.StringF(HTTP::EProxyAddress,
		                        RHTTPSession::GetTable()));
		iConnInfo.SetPropertyL(iStringPool.StringF(HTTP::EProxyAddress,
		                      RHTTPSession::GetTable()), proxyAddress);

		iConnInfo.RemoveProperty(iStringPool.StringF(HTTP::EProxyUsage,
		                        RHTTPSession::GetTable()));
		if (iUsage)
		{
		    iConnInfo.SetPropertyL(iStringPool.StringF(HTTP::EProxyUsage,
		                          RHTTPSession::GetTable()), iStringPool.StringF(HTTP::EUseProxy,
		                                  RHTTPSession::GetTable()));
		}
		else
		{
		    iConnInfo.SetPropertyL(iStringPool.StringF(HTTP::EProxyUsage,
		                          RHTTPSession::GetTable()), iStringPool.StringF(HTTP::EDoNotUseProxy,
		                                  RHTTPSession::GetTable()));
		}
    	
   	}  
    

    // Cleanup strings.
    iProxyAddress.Close();
    iExceptions.Close();
}