1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-15 16:29:34 +00:00

add a convenience function for determining if an address is an IP address, and when picking a favicon in the Mac UI's tracker tab, use the full IP address when applicable

This commit is contained in:
Mitchell Livingston 2010-02-01 23:52:46 +00:00
parent 8f0f6679aa
commit 205b21dca3
3 changed files with 20 additions and 4 deletions

View file

@ -40,6 +40,7 @@
#include "fdlimit.h"
#include "ConvertUTF.h"
#include "list.h"
#include "net.h"
#include "utils.h"
#include "platform.h"
#include "version.h"
@ -932,6 +933,12 @@ tr_httpIsValidURL( const char * url )
return tr_httpParseURL( url, -1, NULL, NULL, NULL ) == 0;
}
tr_bool tr_addressIsIP( const char * address )
{
tr_address tempAddr;
return tr_pton(address, &tempAddr) != NULL;
}
int
tr_httpParseURL( const char * url_in,
int len,

View file

@ -440,6 +440,9 @@ void tr_hex_to_sha1( uint8_t * out, const char * hex ) TR_GNUC_NONNULL(1,2);
/** @brief return TRUE if the url is a http, https, or ftp url that Transmission understands */
tr_bool tr_httpIsValidURL( const char * url ) TR_GNUC_NONNULL(1);
/** @brief convenience function to determine if an address is an IP address (IPv4 or IPv6) */
tr_bool tr_addressIsIP( const char * address );
/** @brief parse a URL into its component parts
@return zero on success or an error number if an error occurred */
int tr_httpParseURL( const char * url,

View file

@ -25,6 +25,7 @@
#import "TrackerCell.h"
#import "NSApplicationAdditions.h"
#import "TrackerNode.h"
#import "utils.h"
#define PADDING_HORIZONAL 3.0
#define PADDING_STATUS_HORIZONAL 3.0
@ -194,15 +195,20 @@ NSMutableSet * fTrackerIconLoading;
- (NSImage *) favIcon
{
NSURL * address = [NSURL URLWithString: [(TrackerNode *)[self objectValue] fullAnnounceAddress]];
NSArray * hostComponents = [[address host] componentsSeparatedByString: @"."];
NSString * 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 ([hostComponents count] > 1)
if (separable && [hostComponents count] > 1)
baseAddress = [NSString stringWithFormat: @"http://%@.%@",
[hostComponents objectAtIndex: [hostComponents count] - 2], [hostComponents lastObject]];
[hostComponents objectAtIndex: [hostComponents count]-2], [hostComponents lastObject]];
else
baseAddress = [NSString stringWithFormat: @"http://%@", [hostComponents lastObject]];
baseAddress = [NSString stringWithFormat: @"http://%@", host];
id icon = [fTrackerIconCache objectForKey: baseAddress];
if (!icon && ![fTrackerIconLoading containsObject: baseAddress])