mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 10:28:32 +00:00
(trunk) #3817 "Use the OS' proxy support" -- implemented for Qt
This commit is contained in:
@@ -13,6 +13,10 @@
|
|||||||
#ifndef TR_HTTP_H
|
#ifndef TR_HTTP_H
|
||||||
#define TR_HTTP_H
|
#define TR_HTTP_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
struct tr_address;
|
struct tr_address;
|
||||||
|
|
||||||
void tr_webInit( tr_session * session );
|
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 );
|
char* tr_http_unescape( const char * str, int len );
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QNetworkProxy>
|
||||||
|
#include <QNetworkProxyFactory>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
@@ -26,12 +28,15 @@
|
|||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
#include <libtransmission/transmission.h>
|
#include <libtransmission/transmission.h>
|
||||||
#include <libtransmission/bencode.h>
|
#include <libtransmission/bencode.h>
|
||||||
#include <libtransmission/json.h>
|
#include <libtransmission/json.h>
|
||||||
#include <libtransmission/rpcimpl.h>
|
#include <libtransmission/rpcimpl.h>
|
||||||
#include <libtransmission/utils.h> /* tr_free */
|
#include <libtransmission/utils.h> // tr_free
|
||||||
#include <libtransmission/version.h> /* LONG_VERSION */
|
#include <libtransmission/version.h> // LONG_VERSION
|
||||||
|
#include <libtransmission/web.h>
|
||||||
|
|
||||||
#include "add-data.h"
|
#include "add-data.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
@@ -299,6 +304,37 @@ Session :: restart( )
|
|||||||
start( );
|
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
|
void
|
||||||
Session :: start( )
|
Session :: start( )
|
||||||
{
|
{
|
||||||
@@ -322,6 +358,7 @@ Session :: start( )
|
|||||||
tr_bencInitDict( &settings, 0 );
|
tr_bencInitDict( &settings, 0 );
|
||||||
tr_sessionLoadSettings( &settings, myConfigDir.toUtf8().constData(), "qt" );
|
tr_sessionLoadSettings( &settings, myConfigDir.toUtf8().constData(), "qt" );
|
||||||
mySession = tr_sessionInit( "qt", myConfigDir.toUtf8().constData(), true, &settings );
|
mySession = tr_sessionInit( "qt", myConfigDir.toUtf8().constData(), true, &settings );
|
||||||
|
tr_sessionSetWebConfigFunc( mySession, curlConfigFunc );
|
||||||
tr_bencFree( &settings );
|
tr_bencFree( &settings );
|
||||||
|
|
||||||
tr_ctor * ctor = tr_ctorNew( mySession );
|
tr_ctor * ctor = tr_ctorNew( mySession );
|
||||||
|
|||||||
Reference in New Issue
Block a user