Changeset 12336


Ignore:
Timestamp:
Apr 7, 2011, 11:29:05 PM (11 years ago)
Author:
livings124
Message:

catch invalid addresses when loading tracker favicons

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/TrackerCell.m

    r11617 r12336  
    197197- (NSImage *) favIcon
    198198{
     199    id icon = nil;
    199200    NSURL * address = [NSURL URLWithString: [(TrackerNode *)[self objectValue] fullAnnounceAddress]];
    200     NSString * host = [address host];
    201    
    202     //don't try to parse ip address
    203     const BOOL separable = !tr_addressIsIP([host UTF8String]);
    204    
    205     NSArray * hostComponents = separable ? [host componentsSeparatedByString: @"."] : nil;
    206    
    207     //let's try getting the tracker address without using any subdomains
    208     NSString * baseAddress;
    209     if (separable && [hostComponents count] > 1)
    210         baseAddress = [NSString stringWithFormat: @"http://%@.%@",
    211                         [hostComponents objectAtIndex: [hostComponents count]-2], [hostComponents lastObject]];
    212     else
    213         baseAddress = [NSString stringWithFormat: @"http://%@", host];
    214    
    215     id icon = [fTrackerIconCache objectForKey: baseAddress];
    216     if (!icon && ![fTrackerIconLoading containsObject: baseAddress])
    217     {
    218         [fTrackerIconLoading addObject: baseAddress];
    219         [NSThread detachNewThreadSelector: @selector(loadTrackerIcon:) toTarget: self withObject: baseAddress];
    220     }
    221    
     201    NSString * host;
     202    if ((host = [address host]))
     203    {
     204        //don't try to parse ip address
     205        const BOOL separable = !tr_addressIsIP([host UTF8String]);
     206       
     207        NSArray * hostComponents = separable ? [host componentsSeparatedByString: @"."] : nil;
     208       
     209        //let's try getting the tracker address without using any subdomains
     210        NSString * baseAddress;
     211        if (separable && [hostComponents count] > 1)
     212            baseAddress = [NSString stringWithFormat: @"http://%@.%@",
     213                            [hostComponents objectAtIndex: [hostComponents count]-2], [hostComponents lastObject]];
     214        else
     215            baseAddress = [NSString stringWithFormat: @"http://%@", host];
     216       
     217        icon = [fTrackerIconCache objectForKey: baseAddress];
     218        if (!icon && ![fTrackerIconLoading containsObject: baseAddress])
     219        {
     220            [fTrackerIconLoading addObject: baseAddress];
     221            [NSThread detachNewThreadSelector: @selector(loadTrackerIcon:) toTarget: self withObject: baseAddress];
     222        }
     223    }
     224       
    222225    return (icon && icon != [NSNull null]) ? icon : [NSImage imageNamed: @"FavIcon.png"];
    223226}
Note: See TracChangeset for help on using the changeset viewer.