(trunk) #3817 "Use the OS' proxy support" -- implemented for Qt

This commit is contained in:
Charles Kerr
2010-12-11 21:27:15 +00:00
parent 5d72e8b7f7
commit 006014edab
2 changed files with 47 additions and 2 deletions

View File

@@ -13,6 +13,10 @@
#ifndef TR_HTTP_H
#define TR_HTTP_H
#ifdef __cplusplus
extern "C" {
#endif
struct tr_address;
void tr_webInit( tr_session * session );
@@ -58,4 +62,8 @@ void tr_http_escape( struct evbuffer *out, const char *str, int len, tr_bool esc
char* tr_http_unescape( const char * str, int len );
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -19,6 +19,8 @@
#include <QCoreApplication>
#include <QDesktopServices>
#include <QMessageBox>
#include <QNetworkProxy>
#include <QNetworkProxyFactory>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QSet>
@@ -26,12 +28,15 @@
#include <QStyle>
#include <QTextStream>
#include <curl/curl.h>
#include <libtransmission/transmission.h>
#include <libtransmission/bencode.h>
#include <libtransmission/json.h>
#include <libtransmission/rpcimpl.h>
#include <libtransmission/utils.h> /* tr_free */
#include <libtransmission/version.h> /* LONG_VERSION */
#include <libtransmission/utils.h> // tr_free
#include <libtransmission/version.h> // LONG_VERSION
#include <libtransmission/web.h>
#include "add-data.h"
#include "prefs.h"
@@ -299,6 +304,37 @@ Session :: restart( )
start( );
}
static void
curlConfigFunc( tr_session * session UNUSED, void * vcurl, const char * destination )
{
CURL * easy = vcurl;
const QUrl url( destination );
const QNetworkProxyQuery query( url );
QList<QNetworkProxy> proxyList = QNetworkProxyFactory :: systemProxyForQuery( query );
foreach( QNetworkProxy proxy, proxyList )
{
long type = -1;
switch( proxy.type( ) ) {
case QNetworkProxy::HttpProxy: type = CURLPROXY_HTTP; break;
case QNetworkProxy::Socks5Proxy: type = CURLPROXY_SOCKS5; break;
default: break;
}
if( type != -1 ) {
curl_easy_setopt( easy, CURLOPT_PROXY, proxy.hostName().toUtf8().data() );
curl_easy_setopt( easy, CURLOPT_PROXYPORT, long(proxy.port()) );
curl_easy_setopt( easy, CURLOPT_PROXYTYPE, type );
const QString user = proxy.user();
const QString pass = proxy.password();
if( !user.isEmpty() && !pass.isEmpty() )
curl_easy_setopt( easy, CURLOPT_PROXYUSERPWD, (user+":"+pass).toUtf8().data() );
return;
}
}
}
void
Session :: start( )
{
@@ -322,6 +358,7 @@ Session :: start( )
tr_bencInitDict( &settings, 0 );
tr_sessionLoadSettings( &settings, myConfigDir.toUtf8().constData(), "qt" );
mySession = tr_sessionInit( "qt", myConfigDir.toUtf8().constData(), true, &settings );
tr_sessionSetWebConfigFunc( mySession, curlConfigFunc );
tr_bencFree( &settings );
tr_ctor * ctor = tr_ctorNew( mySession );