~ubuntu-branches/ubuntu/jaunty/transmission/jaunty-security

« back to all changes in this revision

Viewing changes to libtransmission/torrent.c

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Benner
  • Date: 2007-10-29 19:53:02 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20071029195302-gyy129sjmci7ezel
Tags: 0.91.dfsg-1
* New upstream release (Closes: #448516).
* Using manpages from source package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: torrent.c 3492 2007-10-21 15:47:26Z charles $
 
2
 * $Id: torrent.c 3618 2007-10-28 19:42:46Z charles $
3
3
 *
4
4
 * Copyright (c) 2005-2007 Transmission authors and contributors
5
5
 *
257
257
torrentRealInit( tr_handle  * h,
258
258
                 tr_torrent * tor,
259
259
                 const char * destination,
 
260
                 int          destinationIsFallback,
260
261
                 int          isPaused )
261
262
{
262
263
    int doStart;
267
268
   
268
269
    tr_globalLock( h );
269
270
 
270
 
    tor->destination = tr_strdup( destination );
271
 
 
272
271
    tor->handle   = h;
273
272
    tor->pexDisabled = 0;
274
273
 
339
338
 
340
339
    uncheckedPieces = tr_bitfieldNew( tor->info.pieceCount );
341
340
 
342
 
    loaded = tr_fastResumeLoad( tor, uncheckedPieces );
 
341
    loaded = tr_fastResumeLoad( tor, ~0, uncheckedPieces, destination, destinationIsFallback );
343
342
    assert( tor->destination != NULL );
344
343
 
345
344
    /* the `paused' flag has highest precedence...
449
448
    return ret;
450
449
}
451
450
 
 
451
static tr_torrent *
 
452
tr_torrentInitImpl( tr_handle   * h,
 
453
                    const char  * path,
 
454
                    const char  * destination,
 
455
                    int           destinationIsFallback,
 
456
                    int           isPaused,
 
457
                    int         * error )
 
458
{
 
459
    int val;
 
460
    int tmpError;
 
461
    tr_torrent * tor = NULL;
 
462
 
 
463
    if( !error )
 
464
         error = &tmpError;
 
465
 
 
466
    if(( val = tr_torrentParse( h, path, destination, NULL )))
 
467
        *error = val;
 
468
    else if(!(( tor = tr_new0( tr_torrent, 1 ))))
 
469
        *error = TR_EOTHER;
 
470
    else {
 
471
        tr_metainfoParseFile( &tor->info, h->tag, path, TRUE );
 
472
        torrentRealInit( h, tor, destination, destinationIsFallback, isPaused );
 
473
    }
 
474
 
 
475
    return tor;
 
476
}
 
477
 
452
478
tr_torrent *
453
479
tr_torrentInit( tr_handle   * h,
454
480
                const char  * path,
456
482
                int           isPaused,
457
483
                int         * error )
458
484
{
459
 
    int val;
460
 
    int tmpError;
461
 
    tr_torrent * tor = NULL;
462
 
 
463
 
    if( !error )
464
 
         error = &tmpError;
465
 
 
466
 
    if(( val = tr_torrentParse( h, path, destination, NULL )))
467
 
        *error = val;
468
 
    else if(!(( tor = tr_new0( tr_torrent, 1 ))))
469
 
        *error = TR_EOTHER;
470
 
    else {
471
 
        tr_metainfoParseFile( &tor->info, h->tag, path, TRUE );
472
 
        torrentRealInit( h, tor, destination, isPaused );
473
 
    }
474
 
 
475
 
    return tor;
 
485
    return tr_torrentInitImpl( h, path, destination, FALSE, isPaused, error );
 
486
}
 
487
 
 
488
tr_torrent *
 
489
tr_torrentLoad( tr_handle    * h,
 
490
                const char   * metainfoFilename,
 
491
                const char   * destination,
 
492
                int            isPaused,
 
493
                int          * error )
 
494
{
 
495
    return tr_torrentInitImpl( h, metainfoFilename, destination, TRUE, isPaused, error );
476
496
}
477
497
 
478
498
int
520
540
        *error = TR_EOTHER;
521
541
    else {
522
542
        tr_metainfoParseHash( &tor->info, h->tag, hashStr );
523
 
        torrentRealInit( h, tor, destination, isPaused );
 
543
        torrentRealInit( h, tor, destination, FALSE, isPaused );
524
544
    }
525
545
 
526
546
    return tor;
573
593
        *error = TR_EOTHER;
574
594
    else {
575
595
        tr_metainfoParseData( &tor->info, h->tag, data, size, TRUE );
576
 
        torrentRealInit( h, tor, destination, isPaused );
 
596
        torrentRealInit( h, tor, destination, FALSE, isPaused );
577
597
    }
578
598
 
579
599
    return tor;
1008
1028
 
1009
1029
    if( !tor->isRunning )
1010
1030
    {
 
1031
        if( !tor->uncheckedPieces )
 
1032
            tor->uncheckedPieces = tr_bitfieldNew( tor->info.pieceCount );
 
1033
        tr_fastResumeLoad( tor, TR_FR_PROGRESS, tor->uncheckedPieces, tor->destination, FALSE );
1011
1034
        tor->isRunning = 1;
1012
1035
        tr_ioRecheckAdd( tor, checkAndStartCB );
1013
1036
    }
1303
1326
    ret += length;
1304
1327
    return ret;
1305
1328
}
1306