Changeset 1180


Ignore:
Timestamp:
Dec 8, 2006, 4:43:20 PM (15 years ago)
Author:
livings124
Message:

better logging

Location:
branches/multitracker/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/multitracker/libtransmission/metainfo.c

    r1173 r1180  
    191191    /* We won't need this anymore */
    192192    free( buf );
    193    
     193       
     194    /* Comment info */
     195    if( ( val = tr_bencDictFind( &meta, "comment.utf-8" ) ) || ( val = tr_bencDictFind( &meta, "comment" ) ) )
     196    {
     197        strcatUTF8( inf->comment, val->val.s.s );
     198    }
     199   
     200    /* Creator info */
     201    if( ( val = tr_bencDictFind( &meta, "created by.utf-8" ) ) || ( val = tr_bencDictFind( &meta, "created by" ) ) )
     202    {
     203        strcatUTF8( inf->creator, val->val.s.s );
     204    }
     205   
     206    /* Date created */
     207    if( ( val = tr_bencDictFind( &meta, "creation date" ) ) )
     208    {
     209        inf->dateCreated = val->val.i;
     210    }
     211    else
     212    {
     213        inf->dateCreated = 0;
     214    }
     215
     216    /* Piece length */
     217    if( !( val = tr_bencDictFind( beInfo, "piece length" ) ) )
     218    {
     219        tr_err( "No \"piece length\" entry" );
     220        tr_bencFree( &meta );
     221        return 1;
     222    }
     223    inf->pieceSize = val->val.i;
     224
     225    /* Hashes */
     226    val = tr_bencDictFind( beInfo, "pieces" );
     227    if( val->val.s.i % SHA_DIGEST_LENGTH )
     228    {
     229        tr_err( "Invalid \"piece\" string (size is %d)", val->val.s.i );
     230        tr_bencFree( &meta );
     231        return 1;
     232    }
     233    inf->pieceCount = val->val.s.i / SHA_DIGEST_LENGTH;
     234    inf->pieces = (uint8_t *) val->val.s.s; /* Ugly, but avoids a memcpy */
     235    val->val.s.s = NULL;
     236
     237    /* TODO add more tests so we don't crash on weird files */
     238
     239    inf->totalSize = 0;
     240    if( ( list = tr_bencDictFind( beInfo, "files" ) ) )
     241    {
     242        /* Multi-file mode */
     243        int j;
     244
     245        val = tr_bencDictFind( beInfo, "name.utf-8" );
     246        if( NULL == val )
     247        {
     248            val = tr_bencDictFind( beInfo, "name" );
     249        }
     250        strcatUTF8( inf->name, val->val.s.s );
     251
     252        inf->multifile = 1;
     253        inf->fileCount = list->val.l.count;
     254        inf->files     = calloc( inf->fileCount * sizeof( tr_file_t ), 1 );
     255
     256        for( i = 0; i < list->val.l.count; i++ )
     257        {
     258            val = tr_bencDictFind( &list->val.l.vals[i], "path.utf-8" );
     259            if( NULL == val )
     260            {
     261                val = tr_bencDictFind( &list->val.l.vals[i], "path" );
     262            }
     263            strcatUTF8( inf->files[i].name, inf->name );
     264            for( j = 0; j < val->val.l.count; j++ )
     265            {
     266                strcatUTF8( inf->files[i].name, "/" );
     267                strcatUTF8( inf->files[i].name,
     268                            val->val.l.vals[j].val.s.s );
     269            }
     270            val = tr_bencDictFind( &list->val.l.vals[i], "length" );
     271            inf->files[i].length  = val->val.i;
     272            inf->totalSize       += val->val.i;
     273        }
     274
     275    }
     276    else
     277    {
     278        /* Single-file mode */
     279        inf->multifile = 0;
     280        inf->fileCount = 1;
     281        inf->files     = calloc( sizeof( tr_file_t ), 1 );
     282
     283        val = tr_bencDictFind( beInfo, "name.utf-8" );
     284        if( NULL == val )
     285        {
     286            val = tr_bencDictFind( beInfo, "name" );
     287        }
     288        strcatUTF8( inf->files[0].name, val->val.s.s );
     289        strcatUTF8( inf->name, val->val.s.s );
     290       
     291        val = tr_bencDictFind( beInfo, "length" );
     292        inf->files[0].length  = val->val.i;
     293        inf->totalSize       += val->val.i;
     294    }
     295
     296    if( (uint64_t) inf->pieceCount !=
     297        ( inf->totalSize + inf->pieceSize - 1 ) / inf->pieceSize )
     298    {
     299        tr_err( "Size of hashes and files don't match" );
     300        free( inf->pieces );
     301        tr_bencFree( &meta );
     302        return 1;
     303    }
     304   
     305    /* Announce-list */
    194306    address = calloc( sizeof( char ), 256 );
    195307    announce = calloc( sizeof( char ), MAX_PATH_LENGTH );
     
    256368    }
    257369
    258     /*tr_err( "announce-list:" );
    259     if( !inf->trackerAnnounceTiers )
    260         tr_err( "no announce-list provided", i );
    261     for( i = 0; i < inf->trackerAnnounceTiers; i++ )
    262     {
    263         tr_err( "list %d:", i );
    264         for (announceItem = inf->trackerAnnounceList[i]; announceItem != NULL; announceItem = announceItem->nextItem)
    265         {
    266             tr_err( "%s:%d%s", announceItem->address, announceItem->port, announceItem->announce );
    267         }
    268     }*/
     370   
     371    if( inf->trackerAnnounceTiers )
     372    {
     373        tr_inf( "announce-list for \"%s\":", inf->name );
     374        for( i = 0; i < inf->trackerAnnounceTiers; i++ )
     375        {
     376            tr_inf( "list %d:", i );
     377            for( announceItem = inf->trackerAnnounceList[i]; announceItem != NULL; announceItem = announceItem->nextItem )
     378            {
     379                tr_inf( "%s:%d%s", announceItem->address, announceItem->port, announceItem->announce );
     380            }
     381        }
     382    }
     383    else
     384    {
     385        tr_inf( "no announce-list provided for \"%s\"", inf->name );
     386    }
    269387   
    270388    /* Regular announce value */
     
    281399        }
    282400       
    283         if ( !parseAnnounce( val->val.s.s, address, &port, announce ) )
     401        if( !parseAnnounce( val->val.s.s, address, &port, announce ) )
    284402        {
    285403            tr_err( "Invalid announce URL (%s)", val->val.s.s );
     
    299417        inf->trackerAnnounceList[0]->port = port;
    300418        snprintf( inf->trackerAnnounceList[0]->announce, MAX_PATH_LENGTH, "%s", announce );
     419       
     420        tr_inf( "announce for \"%s\": %s:%d%s", inf->name, address, port, announce );
    301421    }
    302422   
    303423    free( address );
    304424    free( announce );
    305        
    306     /* Comment info */
    307     if( ( val = tr_bencDictFind( &meta, "comment.utf-8" ) ) || ( val = tr_bencDictFind( &meta, "comment" ) ) )
    308     {
    309         strcatUTF8( inf->comment, val->val.s.s );
    310     }
    311    
    312     /* Creator info */
    313     if( ( val = tr_bencDictFind( &meta, "created by.utf-8" ) ) || ( val = tr_bencDictFind( &meta, "created by" ) ) )
    314     {
    315         strcatUTF8( inf->creator, val->val.s.s );
    316     }
    317    
    318     /* Date created */
    319     if( ( val = tr_bencDictFind( &meta, "creation date" ) ) )
    320     {
    321         inf->dateCreated = val->val.i;
    322     }
    323     else
    324     {
    325         inf->dateCreated = 0;
    326     }
    327 
    328     /* Piece length */
    329     if( !( val = tr_bencDictFind( beInfo, "piece length" ) ) )
    330     {
    331         tr_err( "No \"piece length\" entry" );
    332         tr_bencFree( &meta );
    333         return 1;
    334     }
    335     inf->pieceSize = val->val.i;
    336 
    337     /* Hashes */
    338     val = tr_bencDictFind( beInfo, "pieces" );
    339     if( val->val.s.i % SHA_DIGEST_LENGTH )
    340     {
    341         tr_err( "Invalid \"piece\" string (size is %d)", val->val.s.i );
    342         tr_bencFree( &meta );
    343         return 1;
    344     }
    345     inf->pieceCount = val->val.s.i / SHA_DIGEST_LENGTH;
    346     inf->pieces = (uint8_t *) val->val.s.s; /* Ugly, but avoids a memcpy */
    347     val->val.s.s = NULL;
    348 
    349     /* TODO add more tests so we don't crash on weird files */
    350 
    351     inf->totalSize = 0;
    352     if( ( list = tr_bencDictFind( beInfo, "files" ) ) )
    353     {
    354         /* Multi-file mode */
    355         int j;
    356 
    357         val = tr_bencDictFind( beInfo, "name.utf-8" );
    358         if( NULL == val )
    359         {
    360             val = tr_bencDictFind( beInfo, "name" );
    361         }
    362         strcatUTF8( inf->name, val->val.s.s );
    363 
    364         inf->multifile = 1;
    365         inf->fileCount = list->val.l.count;
    366         inf->files     = calloc( inf->fileCount * sizeof( tr_file_t ), 1 );
    367 
    368         for( i = 0; i < list->val.l.count; i++ )
    369         {
    370             val = tr_bencDictFind( &list->val.l.vals[i], "path.utf-8" );
    371             if( NULL == val )
    372             {
    373                 val = tr_bencDictFind( &list->val.l.vals[i], "path" );
    374             }
    375             strcatUTF8( inf->files[i].name, inf->name );
    376             for( j = 0; j < val->val.l.count; j++ )
    377             {
    378                 strcatUTF8( inf->files[i].name, "/" );
    379                 strcatUTF8( inf->files[i].name,
    380                             val->val.l.vals[j].val.s.s );
    381             }
    382             val = tr_bencDictFind( &list->val.l.vals[i], "length" );
    383             inf->files[i].length  = val->val.i;
    384             inf->totalSize       += val->val.i;
    385         }
    386 
    387     }
    388     else
    389     {
    390         /* Single-file mode */
    391         inf->multifile = 0;
    392         inf->fileCount = 1;
    393         inf->files     = calloc( sizeof( tr_file_t ), 1 );
    394 
    395         val = tr_bencDictFind( beInfo, "name.utf-8" );
    396         if( NULL == val )
    397         {
    398             val = tr_bencDictFind( beInfo, "name" );
    399         }
    400         strcatUTF8( inf->files[0].name, val->val.s.s );
    401         strcatUTF8( inf->name, val->val.s.s );
    402        
    403         val = tr_bencDictFind( beInfo, "length" );
    404         inf->files[0].length  = val->val.i;
    405         inf->totalSize       += val->val.i;
    406     }
    407 
    408     if( (uint64_t) inf->pieceCount !=
    409         ( inf->totalSize + inf->pieceSize - 1 ) / inf->pieceSize )
    410     {
    411         tr_err( "Size of hashes and files don't match" );
    412         free( inf->pieces );
    413         tr_bencFree( &meta );
    414         return 1;
    415     }
    416425
    417426    tr_bencFree( &meta );
  • branches/multitracker/libtransmission/tracker.c

    r1179 r1180  
    551551{
    552552    tr_torrent_t * tor = tc->tor;
    553 
    554553    char           start;
    555554
Note: See TracChangeset for help on using the changeset viewer.