Changeset 1192


Ignore:
Timestamp:
Dec 13, 2006, 5:03:14 AM (15 years ago)
Author:
joshe
Message:

Simplify the address and announce strings a bit.
Fix a couple related memory leaks as well.
(I didn't test this but let's pretend I did)

Location:
branches/multitracker/libtransmission
Files:
6 edited

Legend:

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

    r1191 r1192  
    3333
    3434static void _strcatUTF8( char *, int, char * );
    35 static int parseAnnounce( char * original, char * address, int * port, char * announce );
    36 
    37 static int parseAnnounce( char * original, char * address, int * port, char * announce )
    38 {
    39     char * colon, * slash;
    40    
    41     /* Skip spaces */
    42     while( *original && *original == ' ' )
    43     {
    44         original++;
    45     }
    46 
    47     /* Parse announce URL */
    48     if( strncmp( original, "http://", 7 ) )
    49     {
    50         return 0;
    51     }
    52    
    53     colon = strchr( original + 7, ':' );
    54     slash = strchr( original + 7, '/' );
    55     if( colon && colon < slash )
    56     {
    57         memcpy( address, original + 7, (long) colon - (long) original - 7 );
    58         *port = atoi( colon + 1 );
    59         snprintf( announce, MAX_PATH_LENGTH, "%s", slash );
    60        
    61         return 1;
    62     }
    63     else if( slash )
    64     {
    65         memcpy( address, original + 7, (long) slash - (long) original - 7 );
    66         *port = 80;
    67         snprintf( announce, MAX_PATH_LENGTH, "%s", slash );   
    68        
    69         return 1;
    70     }
    71     else
    72     {
    73         return 0;
    74     }
    75 }
    7635
    7736/***********************************************************************
     
    304263   
    305264    /* Announce-list */
    306     address = calloc( sizeof( char ), TR_ADDRLEN );
    307     announce = calloc( sizeof( char ), MAX_PATH_LENGTH );
    308    
    309265    tiersSet = 0;
    310266    if( ( val = tr_bencDictFind( &meta, "announce-list" ) ) )
     
    323279            for( j = 0; j < list[i].val.l.count; j++ )
    324280            {
    325                 if( !parseAnnounce( sublist[j].val.s.s, address, &port, announce ) )
     281                if( tr_httpParseUrl( sublist[j].val.s.s, sublist[j].val.s.i,
     282                                     &address, &port, &announce ) )
    326283                {
    327284                    continue;
     
    351308               
    352309                /* Set values */
    353                 snprintf( announceItem->address, sizeof( announceItem->address ), "%s", address );
    354                 announceItem->port = port;
    355                 snprintf( announceItem->announce, MAX_PATH_LENGTH, "%s", announce );
     310                announceItem->address  = address;
     311                announceItem->port     = port;
     312                announceItem->announce = announce;
    356313               
    357314                inTier++;
     
    389346        {
    390347            tr_err( "No \"announce\" entry" );
    391             free( address );
    392             free( announce );
    393            
    394348            tr_bencFree( &meta );
    395349            return 1;
    396350        }
    397351       
    398         if( !parseAnnounce( val->val.s.s, address, &port, announce ) )
     352        if( tr_httpParseUrl( val->val.s.s, val->val.s.i,
     353                             &address, &port, &announce ) )
    399354        {
    400355            tr_err( "Invalid announce URL (%s)", val->val.s.s );
    401             free( address );
    402             free( announce );
    403            
    404356            tr_bencFree( &meta );
    405357            return 1;
     
    413365       
    414366        inf->trackerAnnounceList[0] = calloc( sizeof( tr_announce_list_item_t ), 1 );
    415         snprintf( inf->trackerAnnounceList[0]->address, sizeof( inf->trackerAnnounceList[0]->address ), "%s", address );
    416         inf->trackerAnnounceList[0]->port = port;
    417         snprintf( inf->trackerAnnounceList[0]->announce, MAX_PATH_LENGTH, "%s", announce );
     367        inf->trackerAnnounceList[0]->address  = address;
     368        inf->trackerAnnounceList[0]->port     = port;
     369        inf->trackerAnnounceList[0]->announce = announce;
    418370       
    419371        tr_inf( "announce for \"%s\": %s:%d%s", inf->name, address, port, announce );
    420372    }
    421    
    422     free( address );
    423     free( announce );
    424373
    425374    tr_bencFree( &meta );
  • branches/multitracker/libtransmission/platform.c

    r1000 r1192  
    115115    snprintf( prefsDirectory, MAX_PATH_LENGTH, "PROGDIR:.transmission" );
    116116#else
    117     snprintf( prefsDirectory, MAX_PATH_LENGTH, "%s/.transmission",
     117    snprintf( prefsDirectory, MAX_PATH_LENGTH, "%s/.transmission-mt",
    118118              tr_getHomeDirectory() );
    119119#endif
  • branches/multitracker/libtransmission/tracker.c

    r1191 r1192  
    3939    char         * trackerid;
    4040   
    41     char           trackerAddress[TR_ADDRLEN];
     41    const char   * trackerAddress;
    4242    int            trackerPort;
    43     char           trackerAnnounce[MAX_PATH_LENGTH];
     43    const char   * trackerAnnounce;
    4444    char           trackerScrape[MAX_PATH_LENGTH];
    4545    int            trackerCanScrape;
     
    168168    tr_announce_list_item_t * announceItem = announcePtr->item;
    169169   
    170     snprintf( tc->trackerAddress, sizeof( tc->trackerAddress ), "%s", announceItem->address );
    171     tc->trackerPort = announceItem->port;
    172     snprintf( tc->trackerAnnounce, MAX_PATH_LENGTH, "%s", announceItem->announce );
     170    tc->trackerAddress  = announceItem->address;
     171    tc->trackerPort     = announceItem->port;
     172    tc->trackerAnnounce = announceItem->announce;
    173173   
    174174    tc->trackerCanScrape = announceToScrape( announceItem->announce, tc->trackerScrape );
     
    950950}
    951951
    952 char * tr_trackerAddress( tr_tracker_t * tc )
     952const char * tr_trackerAddress( tr_tracker_t * tc )
    953953{
    954954    if( !tc )
     
    968968}
    969969
    970 char * tr_trackerAnnounce( tr_tracker_t * tc )
     970const char * tr_trackerAnnounce( tr_tracker_t * tc )
    971971{
    972972    if( !tc )
  • branches/multitracker/libtransmission/tracker.h

    r1178 r1192  
    5757int tr_trackerDownloaded( tr_tracker_t * tc );
    5858
    59 char * tr_trackerAddress( tr_tracker_t * tc );
    60 int tr_trackerPort( tr_tracker_t * tc );
    61 char * tr_trackerAnnounce( tr_tracker_t * tc );
     59const char * tr_trackerAddress ( tr_tracker_t * tc );
     60int          tr_trackerPort    ( tr_tracker_t * tc );
     61const char * tr_trackerAnnounce( tr_tracker_t * tc );
    6262
    6363/***********************************************************************
  • branches/multitracker/libtransmission/transmission.c

    r1191 r1192  
    3131                                       int flags, int * error );
    3232static void torrentReallyStop( tr_torrent_t * );
     33static void freeInfo( tr_info_t * inf );
    3334static void downloadLoop( void * );
    3435static void acceptLoop( void * );
     
    289290        {
    290291            *error = TR_EDUPLICATE;
    291             free( inf->pieces );
    292             free( inf->files );
     292            freeInfo( &tor->info );
    293293            free( tor );
    294294            return NULL;
     
    478478    if( tor->tracker )
    479479    {
    480         snprintf( s->trackerAddress, sizeof( s->trackerAddress ), "%s", tr_trackerAddress( tor->tracker ) );
    481         s->trackerPort = tr_trackerPort( tor->tracker );
    482         snprintf( s->trackerAnnounce, MAX_PATH_LENGTH, "%s", tr_trackerAnnounce( tor->tracker ) );
     480        s->trackerAddress  = tr_trackerAddress(  tor->tracker );
     481        s->trackerPort     = tr_trackerPort(    tor->tracker );
     482        s->trackerAnnounce = tr_trackerAnnounce( tor->tracker );
    483483    }
    484484    else
    485485    {
    486         snprintf( s->trackerAddress, sizeof( s->trackerAddress ), "%s", inf->trackerAnnounceList[0]->address );
    487         s->trackerPort = inf->trackerAnnounceList[0]->port;
    488         snprintf( s->trackerAnnounce, MAX_PATH_LENGTH, "%s", inf->trackerAnnounceList[0]->announce );
     486        s->trackerAddress  = inf->trackerAnnounceList[0]->address;
     487        s->trackerPort     = inf->trackerAnnounceList[0]->port;
     488        s->trackerAnnounce = inf->trackerAnnounceList[0]->announce;
    489489    }
    490490
     
    662662void tr_torrentClose( tr_handle_t * h, tr_torrent_t * tor )
    663663{
    664     int i;
    665     tr_announce_list_item_t * currentAnnounce, * nextAnnounce;
    666    
    667664    tr_info_t * inf = &tor->info;
    668665
     
    688685        free( tor->destination );
    689686    }
     687
     688    freeInfo( inf );
     689
     690    if( tor->prev )
     691    {
     692        tor->prev->next = tor->next;
     693    }
     694    else
     695    {
     696        h->torrentList = tor->next;
     697    }
     698    if( tor->next )
     699    {
     700        tor->next->prev = tor->prev;
     701    }
     702    free( tor );
     703
     704    tr_lockUnlock( &h->acceptLock );
     705}
     706
     707static void freeInfo( tr_info_t * inf )
     708{
     709    int ii;
     710    tr_announce_list_item_t * jj, * dead;
     711
    690712    free( inf->pieces );
    691713    free( inf->files );
    692714   
    693     for( i = 0; i < inf->trackerAnnounceTiers; i++ )
    694     {
    695         for( currentAnnounce = inf->trackerAnnounceList[i]; currentAnnounce != NULL; currentAnnounce = nextAnnounce )
    696         {
    697             nextAnnounce = currentAnnounce->nextItem;
    698             free( currentAnnounce );
    699         }
    700     }
    701 
    702     if( tor->prev )
    703     {
    704         tor->prev->next = tor->next;
    705     }
    706     else
    707     {
    708         h->torrentList = tor->next;
    709     }
    710     if( tor->next )
    711     {
    712         tor->next->prev = tor->prev;
    713     }
    714     free( tor );
    715 
    716     tr_lockUnlock( &h->acceptLock );
     715    for( ii = 0; ii < inf->trackerAnnounceTiers; ii++ )
     716    {
     717        jj = inf->trackerAnnounceList[ii];
     718        while( NULL != jj )
     719        {
     720            dead = jj;
     721            jj = jj->nextItem;
     722            free( dead->address );
     723            free( dead->announce );
     724            free( dead );
     725        }
     726    }
     727    free( inf->trackerAnnounceList );
    717728}
    718729
  • branches/multitracker/libtransmission/transmission.h

    r1191 r1192  
    5252#define TR_DEFAULT_PORT   9090
    5353#define TR_NOERROR        0
    54 #define TR_ADDRLEN        256
    5554
    5655/***********************************************************************
     
    360359    char                trackerError[128];
    361360   
    362     char                trackerAddress[TR_ADDRLEN];
     361    const char        * trackerAddress;
    363362    int                 trackerPort;
    364     char                trackerAnnounce[MAX_PATH_LENGTH];
     363    const char        * trackerAnnounce;
    365364
    366365    float               progress;
     
    403402struct tr_announce_list_item_s
    404403{
    405     char address[TR_ADDRLEN];
    406     int port;
    407     char announce[MAX_PATH_LENGTH];
     404    char * address;
     405    int    port;
     406    char * announce;
    408407   
    409408    tr_announce_list_item_t * nextItem;
Note: See TracChangeset for help on using the changeset viewer.