Changeset 9656


Ignore:
Timestamp:
Dec 2, 2009, 10:56:57 PM (12 years ago)
Author:
charles
Message:

(trunk cli(!)) #2096 "Magnet links - Extension for Peers to Send Metadata Files (BEP #9)" -- add support for adding magnet links as a command-line argument

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/cli.c

    r8889 r9656  
    8989    return "A fast and easy BitTorrent client\n"
    9090           "\n"
    91            "Usage: " MY_NAME " [options] <torrent-filename>";
     91           "Usage: " MY_NAME " [options] <file|url|magnet>";
    9292}
    9393
     
    144144{
    145145    system( finishCall );
     146}
     147
     148static tr_bool waitingOnWeb;
     149
     150static void
     151onTorrentFileDownloaded( tr_session   * session UNUSED,
     152                         long           response_code UNUSED,
     153                         const void   * response,
     154                         size_t         response_byte_count,
     155                         void         * ctor )
     156{
     157    tr_ctorSetMetainfo( ctor, response, response_byte_count );
     158    waitingOnWeb = FALSE;
    146159}
    147160
     
    303316    tr_bool       haveSource;
    304317    tr_bool       haveAnnounce;
     318    uint8_t     * fileContents;
     319    size_t        fileLength;
    305320
    306321    printf( "Transmission %s - http://www.transmissionbt.com/\n",
     
    361376
    362377    ctor = tr_ctorNew( h );
    363     tr_ctorSetMetainfoFromFile( ctor, torrentPath );
     378
     379    fileContents = tr_loadFile( torrentPath, &fileLength );
    364380    tr_ctorSetPaused( ctor, TR_FORCE, showScrape );
     381    if( fileContents != NULL ) {
     382        tr_ctorSetMetainfo( ctor, fileContents, fileLength );
     383    } else if( !memcmp( torrentPath, "magnet:?", 8 ) ) {
     384        tr_ctorSetMagnet( ctor, torrentPath );
     385    } else if( !memcmp( torrentPath, "http", 4 ) ) {
     386        tr_webRun( h, torrentPath, NULL, onTorrentFileDownloaded, ctor );
     387        waitingOnWeb = TRUE;
     388        while( waitingOnWeb ) tr_wait( 1000 );
     389    }
     390    tr_free( fileContents );
    365391
    366392    if( showScrape )
     
    387413                    tr_httpParseURL( scrape, -1, &host, NULL, NULL );
    388414                    ++leftToScrape;
     415
    389416                    tr_webRun( h, url, NULL, scrapeDoneFunc, host );
    390417                    tr_free( url );
Note: See TracChangeset for help on using the changeset viewer.