#5036 Bonjour Service Name Maximum Length Bug

This commit is contained in:
Mitchell Livingston 2012-09-09 05:19:10 +00:00
parent 1acd97b55d
commit dd1a937ce2
1 changed files with 18 additions and 1 deletions

View File

@ -24,6 +24,8 @@
#import "BonjourController.h"
#define BONJOUR_SERVICE_NAME_MAX_LENGTH 63
@implementation BonjourController
BonjourController * fDefaultController = nil;
@ -47,7 +49,22 @@ BonjourController * fDefaultController = nil;
{
[self stop];
NSString * serviceName = [NSString stringWithFormat: @"Transmission Web Interface (%@ - %@)", NSUserName(), [[NSHost currentHost] localizedName]];
//Attempt full length service name
#warning localize?
NSString * mainName = @"Transmission Web Interface";
NSString * details = [NSString stringWithFormat: @"%@ - %@", NSUserName(), [[NSHost currentHost] localizedName]];
NSString * serviceName = [NSString stringWithFormat: @"%@ (%@)", mainName, details];
if ([serviceName length] > BONJOUR_SERVICE_NAME_MAX_LENGTH) {
//Remove Web Interface to shorten name
mainName = @"Transmission";
serviceName = [NSString stringWithFormat: @"%@ (%@)", mainName, details];
if ([serviceName length] > BONJOUR_SERVICE_NAME_MAX_LENGTH) {
//Last resort is to truncate the user name and computer name
serviceName = [serviceName substringToIndex: BONJOUR_SERVICE_NAME_MAX_LENGTH];
}
}NSLog(@"%@", serviceName);
fService = [[NSNetService alloc] initWithDomain: @"" type: @"_http._tcp." name: serviceName port: port];
[fService setDelegate: self];