catch invalid addresses when loading tracker favicons

This commit is contained in:
Mitchell Livingston 2011-04-07 23:29:05 +00:00
parent 6a53f72481
commit b4cdc74706
1 changed files with 23 additions and 20 deletions

View File

@ -196,27 +196,30 @@ NSMutableSet * fTrackerIconLoading;
- (NSImage *) favIcon - (NSImage *) favIcon
{ {
id icon = nil;
NSURL * address = [NSURL URLWithString: [(TrackerNode *)[self objectValue] fullAnnounceAddress]]; NSURL * address = [NSURL URLWithString: [(TrackerNode *)[self objectValue] fullAnnounceAddress]];
NSString * host = [address host]; NSString * host;
if ((host = [address host]))
//don't try to parse ip address
const BOOL separable = !tr_addressIsIP([host UTF8String]);
NSArray * hostComponents = separable ? [host componentsSeparatedByString: @"."] : nil;
//let's try getting the tracker address without using any subdomains
NSString * baseAddress;
if (separable && [hostComponents count] > 1)
baseAddress = [NSString stringWithFormat: @"http://%@.%@",
[hostComponents objectAtIndex: [hostComponents count]-2], [hostComponents lastObject]];
else
baseAddress = [NSString stringWithFormat: @"http://%@", host];
id icon = [fTrackerIconCache objectForKey: baseAddress];
if (!icon && ![fTrackerIconLoading containsObject: baseAddress])
{ {
[fTrackerIconLoading addObject: baseAddress]; //don't try to parse ip address
[NSThread detachNewThreadSelector: @selector(loadTrackerIcon:) toTarget: self withObject: baseAddress]; const BOOL separable = !tr_addressIsIP([host UTF8String]);
NSArray * hostComponents = separable ? [host componentsSeparatedByString: @"."] : nil;
//let's try getting the tracker address without using any subdomains
NSString * baseAddress;
if (separable && [hostComponents count] > 1)
baseAddress = [NSString stringWithFormat: @"http://%@.%@",
[hostComponents objectAtIndex: [hostComponents count]-2], [hostComponents lastObject]];
else
baseAddress = [NSString stringWithFormat: @"http://%@", host];
icon = [fTrackerIconCache objectForKey: baseAddress];
if (!icon && ![fTrackerIconLoading containsObject: baseAddress])
{
[fTrackerIconLoading addObject: baseAddress];
[NSThread detachNewThreadSelector: @selector(loadTrackerIcon:) toTarget: self withObject: baseAddress];
}
} }
return (icon && icon != [NSNull null]) ? icon : [NSImage imageNamed: @"FavIcon.png"]; return (icon && icon != [NSNull null]) ? icon : [NSImage imageNamed: @"FavIcon.png"];