Browse Source

Merge pull request #461 from facebook/nlutsenko.lint

Lint, cleanup and fix analyzer warning.
Nikita Lutsenko 9 năm trước cách đây
mục cha
commit
d09212793c

+ 5 - 6
SocketRocket.podspec

@@ -1,15 +1,15 @@
 Pod::Spec.new do |s|
-  s.name               = "SocketRocket"
+  s.name               = 'SocketRocket'
   s.version            = '0.5.1'
-  s.summary            = 'A conforming WebSocket (RFC 6455) client library.'
+  s.summary            = 'A conforming WebSocket (RFC 6455) client library for iOS, macOS and tvOS.'
   s.homepage           = 'https://github.com/facebook/SocketRocket'
-  s.authors            = 'Square'
+  s.authors            = { 'Nikita Lutsenko' => 'nlutsenko@me.com', 'Dan Federman' => 'federman@squareup.com', 'Mike Lewis' => 'mikelikespie@gmail.com' }
   s.license            = 'BSD'
   s.source             = { :git => 'https://github.com/facebook/SocketRocket.git', :tag => s.version.to_s }
   s.requires_arc       = true
   
   s.source_files       = 'SocketRocket/**/*.{h,m}'
-  s.public_header_files       = 'SocketRocket/*.h'
+  s.public_header_files = 'SocketRocket/*.h'
 
   s.ios.deployment_target  = '6.0'
   s.osx.deployment_target  = '10.8'
@@ -18,6 +18,5 @@ Pod::Spec.new do |s|
   s.ios.frameworks     = 'CFNetwork', 'Security'
   s.osx.frameworks     = 'CoreServices', 'Security'
   s.tvos.frameworks    = 'CFNetwork', 'Security'
-
-  s.libraries          = "icucore"
+  s.libraries          = 'icucore'
 end

+ 0 - 32
SocketRocket.xcodeproj/project.pbxproj

@@ -851,7 +851,6 @@
 				2D42275D1BB4358C000C1A6C /* Sources */,
 				2D42275E1BB4358C000C1A6C /* Frameworks */,
 				2D42275F1BB4358C000C1A6C /* Headers */,
-				2D4227601BB4358C000C1A6C /* Resources */,
 			);
 			buildRules = (
 			);
@@ -869,7 +868,6 @@
 				3345DC831C52ACD70083CCB8 /* Sources */,
 				3345DC851C52ACD70083CCB8 /* Frameworks */,
 				3345DC891C52ACD70083CCB8 /* Headers */,
-				3345DC8C1C52ACD70083CCB8 /* Resources */,
 			);
 			buildRules = (
 			);
@@ -887,7 +885,6 @@
 				81D647601D2CA78800690609 /* Sources */,
 				81D647721D2CA78800690609 /* Frameworks */,
 				81D647761D2CA78800690609 /* Headers */,
-				81D647891D2CA78800690609 /* Resources */,
 			);
 			buildRules = (
 			);
@@ -925,7 +922,6 @@
 				F6396B85153E67EC00345B5E /* Sources */,
 				F668C87C153E91210044DBAC /* Frameworks */,
 				F668C87D153E91210044DBAC /* Headers */,
-				F668C87E153E91210044DBAC /* Resources */,
 			);
 			buildRules = (
 			);
@@ -986,27 +982,6 @@
 /* End PBXProject section */
 
 /* Begin PBXResourcesBuildPhase section */
-		2D4227601BB4358C000C1A6C /* Resources */ = {
-			isa = PBXResourcesBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-		3345DC8C1C52ACD70083CCB8 /* Resources */ = {
-			isa = PBXResourcesBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-		81D647891D2CA78800690609 /* Resources */ = {
-			isa = PBXResourcesBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
 		F62417E114D52F3C003CE997 /* Resources */ = {
 			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
@@ -1017,13 +992,6 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
-		F668C87E153E91210044DBAC /* Resources */ = {
-			isa = PBXResourcesBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
 		F6BDA7FF145900D200FE3253 /* Resources */ = {
 			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;

+ 1 - 1
SocketRocket/Internal/Delegate/SRDelegateController.h

@@ -9,7 +9,7 @@
 
 #import <Foundation/Foundation.h>
 
-#import "SRWebSocket.h"
+#import <SocketRocket/SRWebSocket.h>
 
 NS_ASSUME_NONNULL_BEGIN
 

+ 1 - 1
SocketRocket/Internal/Delegate/SRDelegateController.m

@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 @property (nonatomic, strong, readonly) dispatch_queue_t accessQueue;
 
-@property (atomic, readwrite) SRDelegateAvailableMethods availableDelegateMethods;
+@property (atomic, assign, readwrite) SRDelegateAvailableMethods availableDelegateMethods;
 
 @end
 

+ 1 - 1
SocketRocket/Internal/NSRunLoop+SRWebSocketPrivate.h

@@ -10,4 +10,4 @@
 #import <SocketRocket/NSRunLoop+SRWebSocket.h>
 
 // Empty function that force links the object file for the category.
-extern void import_NSRunLoop_SRWebSocket();
+extern void import_NSRunLoop_SRWebSocket(void);

+ 1 - 1
SocketRocket/Internal/NSURLRequest+SRWebSocketPrivate.h

@@ -10,4 +10,4 @@
 #import <SocketRocket/NSURLRequest+SRWebSocket.h>
 
 // Empty function that force links the object file for the category.
-extern void import_NSURLRequest_SRWebSocket();
+extern void import_NSURLRequest_SRWebSocket(void);

+ 11 - 11
SocketRocket/Internal/Proxy/SRProxyConnect.m

@@ -8,11 +8,12 @@
 //
 
 #import "SRProxyConnect.h"
-#import "SRError.h"
+
 #import "NSRunLoop+SRWebSocket.h"
-#import "SRURLUtilities.h"
-#import "SRLog.h"
 #import "SRConstants.h"
+#import "SRError.h"
+#import "SRLog.h"
+#import "SRURLUtilities.h"
 
 @interface SRProxyConnect() <NSStreamDelegate>
 
@@ -165,14 +166,14 @@
     if ([proxyType isEqualToString:(NSString *)kCFProxyTypeAutoConfigurationURL]) {
         NSURL *pacURL = settings[(NSString *)kCFProxyAutoConfigurationURLKey];
         if (pacURL) {
-            [self _fetchPAC:pacURL];
+            [self _fetchPAC:pacURL withProxySettings:proxySettings];
             return;
         }
     }
     if ([proxyType isEqualToString:(__bridge NSString *)kCFProxyTypeAutoConfigurationJavaScript]) {
         NSString *script = settings[(__bridge NSString *)kCFProxyAutoConfigurationJavaScriptKey];
         if (script) {
-            [self _runPACScript:script];
+            [self _runPACScript:script withProxySettings:proxySettings];
             return;
         }
     }
@@ -208,7 +209,7 @@
     }
 }
 
-- (void)_fetchPAC:(NSURL *)PACurl
+- (void)_fetchPAC:(NSURL *)PACurl withProxySettings:(NSDictionary *)proxySettings
 {
     SRDebugLog(@"SRWebSocket fetchPAC:%@", PACurl);
 
@@ -221,7 +222,7 @@
         if (error) {
             [self _openConnection];
         } else {
-            [self _runPACScript:script];
+            [self _runPACScript:script withProxySettings:proxySettings];
         }
         return;
     }
@@ -240,14 +241,14 @@
         __strong typeof(wself) sself = wself;
         if (!error) {
             NSString *script = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-            [sself _runPACScript:script];
+            [sself _runPACScript:script withProxySettings:proxySettings];
         } else {
             [sself _openConnection];
         }
     }] resume];
 }
 
-- (void)_runPACScript:(NSString *)script
+- (void)_runPACScript:(NSString *)script withProxySettings:(NSDictionary *)proxySettings
 {
     if (!script) {
         [self _openConnection];
@@ -258,8 +259,7 @@
     // Work around <rdar://problem/5530166>.  This dummy call to
     // CFNetworkCopyProxiesForURL initialise some state within CFNetwork
     // that is required by CFNetworkCopyProxiesForAutoConfigurationScript.
-    NSDictionary *empty = nil;
-    CFBridgingRelease(CFNetworkCopyProxiesForURL((__bridge CFURLRef)_url, (__bridge CFDictionaryRef)empty));
+    CFBridgingRelease(CFNetworkCopyProxiesForURL((__bridge CFURLRef)_url, (__bridge CFDictionaryRef)proxySettings));
 
     // Obtain the list of proxies by running the autoconfiguration script
     CFErrorRef err = NULL;

+ 4 - 10
SocketRocket/Internal/RunLoop/SRRunLoopThread.m

@@ -12,21 +12,15 @@
 #import "SRRunLoopThread.h"
 
 @interface SRRunLoopThread ()
+{
+    dispatch_group_t _waitGroup;
+}
 
 @property (nonatomic, strong, readwrite) NSRunLoop *runLoop;
 
 @end
 
-@implementation SRRunLoopThread {
-    dispatch_group_t _waitGroup;
-}
-
-- (void)dealloc
-{
-#if !OS_OBJECT_USE_OBJC_RETAIN_RELEASE
-    dispatch_release(_waitGroup);
-#endif
-}
+@implementation SRRunLoopThread
 
 + (instancetype)sharedThread
 {

+ 0 - 1
SocketRocket/Internal/SRConstants.h

@@ -24,4 +24,3 @@ typedef NS_ENUM(NSInteger, SROpCode)
  Default buffer size that is used for reading/writing to streams.
  */
 extern size_t SRDefaultBufferSize(void);
-

+ 2 - 1
SocketRocket/Internal/Security/SRPinningSecurityPolicy.h

@@ -8,7 +8,8 @@
 //
 
 #import <Foundation/Foundation.h>
-#import "SRSecurityPolicy.h"
+
+#import <SocketRocket/SRSecurityPolicy.h>
 
 NS_ASSUME_NONNULL_BEGIN
 

+ 1 - 0
SocketRocket/Internal/Utilities/SRError.m

@@ -8,6 +8,7 @@
 //
 
 #import "SRError.h"
+
 #import "SRWebSocket.h"
 
 NS_ASSUME_NONNULL_BEGIN

+ 2 - 2
SocketRocket/Internal/Utilities/SRSIMDHelpers.m

@@ -11,7 +11,7 @@
 
 typedef uint8_t uint8x32_t __attribute__((vector_size(32)));
 
-void SRMaskBytesManual(uint8_t *bytes, size_t length, uint8_t *maskKey) {
+static void SRMaskBytesManual(uint8_t *bytes, size_t length, uint8_t *maskKey) {
     for (size_t i = 0; i < length; i++) {
         bytes[i] = bytes[i] ^ maskKey[i % sizeof(uint32_t)];
     }
@@ -25,7 +25,7 @@ void SRMaskBytesManual(uint8_t *bytes, size_t length, uint8_t *maskKey) {
 
  @return A shifted vector.
  */
-uint8x32_t SRShiftVector(uint8x32_t vector, size_t by) {
+static uint8x32_t SRShiftVector(uint8x32_t vector, size_t by) {
     uint8x32_t vectorCopy = vector;
     by = by % _Alignof(uint8x32_t);
 

+ 0 - 20
SocketRocket/Makefile

@@ -1,20 +0,0 @@
-BINS := SocketRocket.framework libSocketRocket.a
-
-all: $(BINS)
-
-HEADERS := SRWebSocket.h
-SRCS := SRWebSocket.m
-OBJS := $(SRCS:%.m=%.o)
-
-CFLAGS += -fobjc-arc
-
-libSocketRocket.a: $(OBJS)
-	$(AR) -rc $(AFLAGS) $@ $^
-
-SocketRocket.framework: libSocketRocket.a
-	mkdir -p $@/Headers
-	cp -f $(HEADERS) $@/Headers
-	cp $^ $@/SocketRocket
-
-clean:
-	rm -r $(OBJS) $(BINS)

+ 1 - 1
SocketRocket/NSRunLoop+SRWebSocket.m

@@ -15,7 +15,7 @@
 #import "SRRunLoopThread.h"
 
 // Required for object file to always be linked.
-extern void import_NSRunLoop_SRWebSocket() { }
+void import_NSRunLoop_SRWebSocket() { }
 
 @implementation NSRunLoop (SRWebSocket)
 

+ 2 - 2
SocketRocket/NSURLRequest+SRWebSocket.h

@@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
  An array of pinned `SecCertificateRef` SSL certificates that `SRWebSocket` will use for validation.
  */
-@property (nullable, nonatomic, strong, readonly) NSArray *SR_SSLPinnedCertificates;
+@property (nullable, nonatomic, copy, readonly) NSArray *SR_SSLPinnedCertificates;
 
 @end
 
@@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
 /**
  An array of pinned `SecCertificateRef` SSL certificates that `SRWebSocket` will use for validation.
  */
-@property (nullable, nonatomic, strong) NSArray *SR_SSLPinnedCertificates;
+@property (nullable, nonatomic, copy) NSArray *SR_SSLPinnedCertificates;
 
 @end
 

+ 6 - 4
SocketRocket/NSURLRequest+SRWebSocket.m

@@ -13,15 +13,17 @@
 #import "NSURLRequest+SRWebSocketPrivate.h"
 
 // Required for object file to always be linked.
-extern void import_NSURLRequest_SRWebSocket() { }
+void import_NSURLRequest_SRWebSocket() { }
 
 NS_ASSUME_NONNULL_BEGIN
 
+static NSString *const SRSSLPinnnedCertificatesKey = @"SocketRocket_SSLPinnedCertificates";
+
 @implementation NSURLRequest (SRWebSocket)
 
 - (nullable NSArray *)SR_SSLPinnedCertificates
 {
-    return [NSURLProtocol propertyForKey:@"SR_SSLPinnedCertificates" inRequest:self];
+    return [NSURLProtocol propertyForKey:SRSSLPinnnedCertificatesKey inRequest:self];
 }
 
 @end
@@ -30,12 +32,12 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (nullable NSArray *)SR_SSLPinnedCertificates
 {
-    return [NSURLProtocol propertyForKey:@"SR_SSLPinnedCertificates" inRequest:self];
+    return [NSURLProtocol propertyForKey:SRSSLPinnnedCertificatesKey inRequest:self];
 }
 
 - (void)setSR_SSLPinnedCertificates:(nullable NSArray *)SR_SSLPinnedCertificates
 {
-    [NSURLProtocol setProperty:SR_SSLPinnedCertificates forKey:@"SR_SSLPinnedCertificates" inRequest:self];
+    [NSURLProtocol setProperty:[SR_SSLPinnedCertificates copy] forKey:SRSSLPinnnedCertificatesKey inRequest:self];
 }
 
 @end

+ 5 - 5
SocketRocket/SRWebSocket.h

@@ -21,7 +21,7 @@ typedef NS_ENUM(NSInteger, SRReadyState) {
 };
 
 typedef NS_ENUM(NSInteger, SRStatusCode) {
-    // 0999: Reserved and not used.
+    // 0-999: Reserved and not used.
     SRStatusCodeNormal = 1000,
     SRStatusCodeGoingAway = 1001,
     SRStatusCodeProtocolError = 1002,
@@ -38,10 +38,10 @@ typedef NS_ENUM(NSInteger, SRStatusCode) {
     SRStatusCodeTryAgainLater = 1013,
     // 1014: Reserved for future use by the WebSocket standard.
     SRStatusCodeTLSHandshake = 1015,
-    // 10161999: Reserved for future use by the WebSocket standard.
-    // 20002999: Reserved for use by WebSocket extensions.
-    // 30003999: Available for use by libraries and frameworks. May not be used by applications. Available for registration at the IANA via first-come, first-serve.
-    // 40004999: Available for use by applications.
+    // 1016-1999: Reserved for future use by the WebSocket standard.
+    // 2000-2999: Reserved for use by WebSocket extensions.
+    // 3000-3999: Available for use by libraries and frameworks. May not be used by applications. Available for registration at the IANA via first-come, first-serve.
+    // 4000-4999: Available for use by applications.
 };
 
 @class SRWebSocket;

+ 7 - 7
SocketRocket/SRWebSocket.m

@@ -1570,28 +1570,28 @@ static inline int32_t validate_dispatch_data_partial_string(NSData *data) {
     if (codepoint == -1) {
         // Check to see if the last byte is valid or whether it was just continuing
         if (!U8_IS_LEAD(str[lastOffset]) || U8_COUNT_TRAIL_BYTES(str[lastOffset]) + lastOffset < (int32_t)size) {
-            
+
             size = -1;
         } else {
             uint8_t leadByte = str[lastOffset];
             U8_MASK_LEAD_BYTE(leadByte, U8_COUNT_TRAIL_BYTES(leadByte));
-            
+
             for (int i = lastOffset + 1; i < offset; i++) {
                 if (U8_IS_SINGLE(str[i]) || U8_IS_LEAD(str[i]) || !U8_IS_TRAIL(str[i])) {
                     size = -1;
                 }
             }
-            
+
             if (size != -1) {
                 size = lastOffset;
             }
         }
     }
-    
+
     if (size != -1 && ![[NSString alloc] initWithBytesNoCopy:(char *)[data bytes] length:size encoding:NSUTF8StringEncoding freeWhenDone:NO]) {
         size = -1;
     }
-    
+
     return size;
 }
 
@@ -1600,14 +1600,14 @@ static inline int32_t validate_dispatch_data_partial_string(NSData *data) {
 // This is a hack, and probably not optimal
 static inline int32_t validate_dispatch_data_partial_string(NSData *data) {
     static const int maxCodepointSize = 3;
-    
+
     for (int i = 0; i < maxCodepointSize; i++) {
         NSString *str = [[NSString alloc] initWithBytesNoCopy:(char *)data.bytes length:data.length - i encoding:NSUTF8StringEncoding freeWhenDone:NO];
         if (str) {
             return (int32_t)data.length - i;
         }
     }
-    
+
     return -1;
 }
 

+ 5 - 5
SocketRocket/SocketRocket.h

@@ -1,15 +1,15 @@
 //
 // Copyright 2012 Square Inc.
 // Portions Copyright (c) 2016-present, Facebook, Inc.
-// 
+//
 // All rights reserved.
-// 
+//
 // This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree. An additional grant 
+// LICENSE file in the root directory of this source tree. An additional grant
 // of patent rights can be found in the PATENTS file in the same directory.
 //
 
-#import <SocketRocket/SRWebSocket.h>
-#import <SocketRocket/SRSecurityPolicy.h>
 #import <SocketRocket/NSRunLoop+SRWebSocket.h>
 #import <SocketRocket/NSURLRequest+SRWebSocket.h>
+#import <SocketRocket/SRSecurityPolicy.h>
+#import <SocketRocket/SRWebSocket.h>

+ 1 - 1
Vendor/xctoolchain

@@ -1 +1 @@
-Subproject commit af8d7f69bf7a5b8e8edd94a139f83fc465b7b64a
+Subproject commit a66c63fe948cf8b4d77a51b69f35459fe0c68973