From dd1a937ce21b2b67204f6c5bf0bf445c80dea746 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 9 Sep 2012 05:19:10 +0000 Subject: [PATCH] #5036 Bonjour Service Name Maximum Length Bug --- macosx/BonjourController.m | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/macosx/BonjourController.m b/macosx/BonjourController.m index 38b71a8b6..0263f2948 100644 --- a/macosx/BonjourController.m +++ b/macosx/BonjourController.m @@ -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];