Ignore:
Timestamp:
Aug 4, 2010, 1:56:51 PM (12 years ago)
Author:
charles
Message:

(2.0x qt) #3481 "crash when accessing a remote session that's password protected" -- fixed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0x/qt/session.cc

    r10868 r11108  
    231231    myPrefs( prefs ),
    232232    mySession( 0 ),
    233     myConfigDir( configDir )
     233    myConfigDir( configDir ),
     234    myNAM( 0 )
    234235{
    235236    myStats.ratio = TR_RATIO_NA;
     
    241242    myCumulativeStats = myStats;
    242243
    243     connect( &myNAM, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*)) );
    244     connect( &myNAM, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SIGNAL(httpAuthenticationRequired()) );
    245244    connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(updatePref(int)) );
    246245}
     
    249248{
    250249    stop( );
     250}
     251
     252QNetworkAccessManager *
     253Session :: networkAccessManager( )
     254{
     255    if( myNAM == 0 )
     256    {
     257        myNAM = new QNetworkAccessManager;
     258
     259        connect( myNAM, SIGNAL(finished(QNetworkReply*)),
     260                 this, SLOT(onFinished(QNetworkReply*)) );
     261
     262        connect( myNAM, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
     263                 this, SIGNAL(httpAuthenticationRequired()) );
     264    }
     265
     266    return myNAM;
    251267}
    252268
     
    258274Session :: stop( )
    259275{
    260     foreach( Reply myReply, myReplies )
    261         myReply.networkReply->abort();
     276    if( myNAM != 0 )
     277    {
     278        myNAM->deleteLater( );
     279        myNAM = 0;
     280    }
     281
    262282    myUrl.clear( );
    263283
     
    281301    if( myPrefs.get<bool>(Prefs::SESSION_IS_REMOTE) )
    282302    {
    283         const int port( myPrefs.get<int>(Prefs::SESSION_REMOTE_PORT) );
    284         const bool auth( myPrefs.get<bool>(Prefs::SESSION_REMOTE_AUTH) );
    285         const QString host( myPrefs.get<QString>(Prefs::SESSION_REMOTE_HOST) );
    286         const QString user( myPrefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME) );
    287         const QString pass( myPrefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD) );
    288 
    289303        QUrl url;
    290304        url.setScheme( "http" );
    291         url.setHost( host );
    292         url.setPort( port );
     305        url.setHost( myPrefs.get<QString>(Prefs::SESSION_REMOTE_HOST) );
     306        url.setPort( myPrefs.get<int>(Prefs::SESSION_REMOTE_PORT) );
    293307        url.setPath( "/transmission/rpc" );
    294         if( auth ) {
    295             url.setUserName( user );
    296             url.setPassword( pass );
     308        if( myPrefs.get<bool>(Prefs::SESSION_REMOTE_AUTH) )
     309        {
     310            url.setUserName( myPrefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME) );
     311            url.setPassword( myPrefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD) );
    297312        }
    298313        myUrl = url;
     
    584599}
    585600
     601#define REQUEST_DATA_PROPERTY_KEY "requestData"
     602
    586603void
    587604Session :: exec( const char * json )
     
    600617            request.setRawHeader( TR_RPC_SESSION_ID_HEADER, mySessionId.toAscii() );
    601618
    602         QBuffer * reqbuf = new QBuffer;
    603         reqbuf->setData( QByteArray( json ) );
    604 
    605         QNetworkReply * reply = myNAM.post( request, reqbuf );
     619        const QByteArray requestData( json );
     620        QNetworkReply * reply = networkAccessManager()->post( request, requestData );
     621        reply->setProperty( REQUEST_DATA_PROPERTY_KEY, requestData );
    606622        connect( reply, SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(dataReadProgress()));
    607623        connect( reply, SIGNAL(uploadProgress(qint64,qint64)), this, SIGNAL(dataSendProgress()));
    608624
    609         Reply myReply;
    610         myReply.networkReply = reply;
    611         myReply.buffer = reqbuf;
    612         myReplies << myReply;
    613625#ifdef DEBUG_HTTP
    614626        std::cerr << "sending " << "POST " << qPrintable( myUrl.path() ) << std::endl;
     
    626638Session :: onFinished( QNetworkReply * reply )
    627639{
    628     QBuffer * buffer;
    629     for( QList<Reply>::iterator i = myReplies.begin(); i != myReplies.end(); ++i )
    630     {
    631         if( reply == i->networkReply )
    632         {
    633             buffer = i->buffer;
    634             myReplies.erase( i );
    635             break;
    636         }
    637     }
    638 
    639640#ifdef DEBUG_HTTP
    640641    std::cerr << "http response header: " << std::endl;
     
    653654        // update it and resubmit the request.
    654655        mySessionId = QString( reply->rawHeader( TR_RPC_SESSION_ID_HEADER ) );
    655         exec( buffer->buffer().constData() );
     656        exec( reply->property( REQUEST_DATA_PROPERTY_KEY ).toByteArray( ).constData( ) );
    656657    }
    657658    else if( reply->error() != QNetworkReply::NoError )
     
    668669    }
    669670
    670     delete buffer;
    671671    reply->deleteLater();
    672672}
Note: See TracChangeset for help on using the changeset viewer.