]> granicus.if.org Git - transmission/commitdiff
#5036 Bonjour Service Name Maximum Length Bug
authorMitchell Livingston <livings124@transmissionbt.com>
Sun, 9 Sep 2012 05:19:10 +0000 (05:19 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Sun, 9 Sep 2012 05:19:10 +0000 (05:19 +0000)
macosx/BonjourController.m

index 38b71a8b66f325e28d79789ea338dbad33bc8d9d..0263f2948285db82c12c6f72fadee053e81135d7 100644 (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];