catch invalid addresses when loading tracker favicons
This commit is contained in:
parent
6a53f72481
commit
b4cdc74706
|
@ -196,29 +196,32 @@ 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"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue