Browse Source

Merge pull request #366 from adam-p/ios-beta

Fix the ClientPlatform on old iOS; enable bindToDevice code
Adam Pritchard 9 years ago
parent
commit
f6b8837fe3
1 changed files with 20 additions and 13 deletions
  1. 20 13
      MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m

+ 20 - 13
MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m

@@ -286,18 +286,31 @@
     // Fill in the rest of the values.
     //
     
-    // Ensure the elements of the ClientPlatform do not contain underscores, as that's what we use to separate the elements.
-    // Like "iOS"
-    NSString *systemName = [[[UIDevice currentDevice] systemName] stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
+    // ClientPlatform must not contain:
+    //   - underscores, which are used by us to separate the constituent parts
+    //   - spaces, which are considered invalid by the server
+    // Like "iOS". Older iOS reports "iPhone OS", which we will convert.
+    NSString *systemName = [[UIDevice currentDevice] systemName];
+    if ([systemName isEqual: @"iPhone OS"]) {
+        systemName = @"iOS";
+    }
+    systemName = [[systemName
+                   stringByReplacingOccurrencesOfString:@"_" withString:@"-"]
+                  stringByReplacingOccurrencesOfString:@" " withString:@"-"];
     // Like "10.2.1"
-    NSString *systemVersion = [[[UIDevice currentDevice]systemVersion] stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
+    NSString *systemVersion = [[[[UIDevice currentDevice]systemVersion]
+                                stringByReplacingOccurrencesOfString:@"_" withString:@"-"]
+                               stringByReplacingOccurrencesOfString:@" " withString:@"-"];
+    
     // "unjailbroken"/"jailbroken"
     NSString *jailbroken = @"unjailbroken";
     if ([JailbreakCheck isDeviceJailbroken]) {
         jailbroken = @"jailbroken";
     }
     // Like "com.psiphon3.browser"
-    NSString *bundleIdentifier = [[[NSBundle mainBundle] bundleIdentifier] stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
+    NSString *bundleIdentifier = [[[[NSBundle mainBundle] bundleIdentifier]
+                                   stringByReplacingOccurrencesOfString:@"_" withString:@"-"]
+                                  stringByReplacingOccurrencesOfString:@" " withString:@"-"];
     
     NSString *clientPlatform = [NSString stringWithFormat:@"%@_%@_%@_%@",
                                 systemName,
@@ -548,15 +561,10 @@
 #pragma mark - GoPsiPsiphonProvider protocol implementation (private)
 
 - (BOOL)bindToDevice:(long)fileDescriptor error:(NSError **)error {
-    /*
-    This code is not currently used, so we won't leave it in untested. However, 
-    this implementation info will probably be useful later.
-     
-    // DEBUG
-    [self logMessage:[NSString stringWithFormat: @"***** DEBUG: bindToDevice called"]];
-    
     // This function is only called in TunnelWholeDevice mode
     
+    // TODO: Does this function ever get called?
+    
     // TODO: Determine if this is robust.
     unsigned int interfaceIndex = if_nametoindex("ap1");
     
@@ -565,7 +573,6 @@
         [self logMessage:[NSString stringWithFormat: @"bindToDevice: setsockopt failed; errno: %d", errno]];
         return FALSE;
     }
-    */
 
     return TRUE;
 }