Changeset 11514


Ignore:
Timestamp:
Dec 11, 2010, 9:27:15 PM (11 years ago)
Author:
charles
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/web.h

    r11512 r11514  
    1313#ifndef TR_HTTP_H
    1414#define TR_HTTP_H
     15
     16#ifdef __cplusplus
     17extern "C" {
     18#endif
    1519
    1620struct tr_address;
     
    5963char* tr_http_unescape( const char * str, int len );
    6064
     65#ifdef __cplusplus
     66}
    6167#endif
     68
     69#endif
  • trunk/qt/session.cc

    r11368 r11514  
    2020#include <QDesktopServices>
    2121#include <QMessageBox>
     22#include <QNetworkProxy>
     23#include <QNetworkProxyFactory>
    2224#include <QNetworkReply>
    2325#include <QNetworkRequest>
     
    2729#include <QTextStream>
    2830
     31#include <curl/curl.h>
     32
    2933#include <libtransmission/transmission.h>
    3034#include <libtransmission/bencode.h>
    3135#include <libtransmission/json.h>
    3236#include <libtransmission/rpcimpl.h>
    33 #include <libtransmission/utils.h> /* tr_free */
    34 #include <libtransmission/version.h> /* LONG_VERSION */
     37#include <libtransmission/utils.h> // tr_free
     38#include <libtransmission/version.h> // LONG_VERSION
     39#include <libtransmission/web.h>
    3540
    3641#include "add-data.h"
     
    300305}
    301306
     307static void
     308curlConfigFunc( tr_session * session UNUSED, void * vcurl, const char * destination )
     309{
     310    CURL * easy = vcurl;
     311    const QUrl url( destination );
     312    const QNetworkProxyQuery query( url );
     313    QList<QNetworkProxy> proxyList = QNetworkProxyFactory :: systemProxyForQuery( query );
     314
     315    foreach( QNetworkProxy proxy, proxyList )
     316    {
     317        long type = -1;
     318
     319        switch( proxy.type( ) ) {
     320            case QNetworkProxy::HttpProxy: type = CURLPROXY_HTTP; break;
     321            case QNetworkProxy::Socks5Proxy: type = CURLPROXY_SOCKS5; break;
     322            default: break;
     323        }
     324
     325        if( type != -1 ) {
     326            curl_easy_setopt( easy, CURLOPT_PROXY, proxy.hostName().toUtf8().data() );
     327            curl_easy_setopt( easy, CURLOPT_PROXYPORT, long(proxy.port()) );
     328            curl_easy_setopt( easy, CURLOPT_PROXYTYPE, type );
     329            const QString user = proxy.user();
     330            const QString pass = proxy.password();
     331            if( !user.isEmpty() && !pass.isEmpty() )
     332                curl_easy_setopt( easy, CURLOPT_PROXYUSERPWD, (user+":"+pass).toUtf8().data() );
     333            return;
     334        }
     335    }
     336}
     337
    302338void
    303339Session :: start( )
     
    323359        tr_sessionLoadSettings( &settings, myConfigDir.toUtf8().constData(), "qt" );
    324360        mySession = tr_sessionInit( "qt", myConfigDir.toUtf8().constData(), true, &settings );
     361        tr_sessionSetWebConfigFunc( mySession, curlConfigFunc );
    325362        tr_bencFree( &settings );
    326363
Note: See TracChangeset for help on using the changeset viewer.