Changeset 10069


Ignore:
Timestamp:
Feb 1, 2010, 11:52:46 PM (12 years ago)
Author:
livings124
Message:

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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils.c

    r10044 r10069  
    4141#include "ConvertUTF.h"
    4242#include "list.h"
     43#include "net.h"
    4344#include "utils.h"
    4445#include "platform.h"
     
    931932
    932933    return tr_httpParseURL( url, -1, NULL, NULL, NULL ) == 0;
     934}
     935
     936tr_bool tr_addressIsIP( const char * address )
     937{
     938    tr_address tempAddr;
     939    return tr_pton(address, &tempAddr) != NULL;
    933940}
    934941
  • trunk/libtransmission/utils.h

    r10031 r10069  
    441441tr_bool tr_httpIsValidURL( const char * url ) TR_GNUC_NONNULL(1);
    442442
     443/** @brief convenience function to determine if an address is an IP address (IPv4 or IPv6) */
     444tr_bool tr_addressIsIP( const char * address );
     445
    443446/** @brief parse a URL into its component parts
    444447    @return zero on success or an error number if an error occurred */
  • trunk/macosx/TrackerCell.m

    r10055 r10069  
    2626#import "NSApplicationAdditions.h"
    2727#import "TrackerNode.h"
     28#import "utils.h"
    2829
    2930#define PADDING_HORIZONAL 3.0
     
    195196{
    196197    NSURL * address = [NSURL URLWithString: [(TrackerNode *)[self objectValue] fullAnnounceAddress]];
    197     NSArray * hostComponents = [[address host] componentsSeparatedByString: @"."];
     198    NSString * host = [address host];
     199   
     200    //don't try to parse ip address
     201    const BOOL separable = !tr_addressIsIP([host UTF8String]);
     202   
     203    NSArray * hostComponents = separable ? [host componentsSeparatedByString: @"."] : nil;
    198204   
    199205    //let's try getting the tracker address without using any subdomains
    200206    NSString * baseAddress;
    201     if ([hostComponents count] > 1)
     207    if (separable && [hostComponents count] > 1)
    202208        baseAddress = [NSString stringWithFormat: @"http://%@.%@",
    203                         [hostComponents objectAtIndex: [hostComponents count] - 2], [hostComponents lastObject]];
     209                        [hostComponents objectAtIndex: [hostComponents count]-2], [hostComponents lastObject]];
    204210    else
    205         baseAddress = [NSString stringWithFormat: @"http://%@", [hostComponents lastObject]];
     211        baseAddress = [NSString stringWithFormat: @"http://%@", host];
    206212   
    207213    id icon = [fTrackerIconCache objectForKey: baseAddress];
Note: See TracChangeset for help on using the changeset viewer.