diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6617491 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +The MIT License + +Copyright 2018 Corsair Memory, Inc + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e56d4e3 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ + +`AppleMail` is a sample plugin demonstrating the [Stream Deck SDK](https://developer.elgato.com/documentation/stream-deck/). + + +# Description + +`AppleMail` is a plugin that displays the number of unread emails in Apple Mail. Pressing on the key will launch Apple Mail. + +Features: + +- code written in Objective-C +- macOS only +- localized +- detects if Apple Mail is running + + +# Installation + +In the Release folder, you can find the file `com.elgato.applemail.streamDeckPlugin`. If you double-click this file on your machine, Stream Deck will install the plugin. + + +# Source code + +The Sources folder contains the source code of the plugin. diff --git a/Release/com.elgato.applemail.streamDeckPlugin b/Release/com.elgato.applemail.streamDeckPlugin new file mode 100644 index 0000000..15ae1d5 Binary files /dev/null and b/Release/com.elgato.applemail.streamDeckPlugin differ diff --git a/Sources/AppleMail.xcodeproj/project.pbxproj b/Sources/AppleMail.xcodeproj/project.pbxproj new file mode 100644 index 0000000..8ea08e5 --- /dev/null +++ b/Sources/AppleMail.xcodeproj/project.pbxproj @@ -0,0 +1,516 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + FA29E473215E7D2300C9F60C /* ESDConnectionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = FA29E46E215E7D2300C9F60C /* ESDConnectionManager.m */; }; + FA29E474215E7D2300C9F60C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = FA29E46F215E7D2300C9F60C /* main.m */; }; + FA80591421623A0D00ED7E12 /* ESDUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = FA80591321623A0D00ED7E12 /* ESDUtilities.m */; }; + FA80591721623C8D00ED7E12 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA80591621623C8D00ED7E12 /* CoreFoundation.framework */; }; + FA80591921623C9200ED7E12 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA80591821623C9200ED7E12 /* AppKit.framework */; }; + FAC7C8172122CE1D000262E7 /* SRDelegateController.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C7E82122CE1D000262E7 /* SRDelegateController.m */; settings = {COMPILER_FLAGS = "-Wno-implicit-retain-self"; }; }; + FAC7C8182122CE1D000262E7 /* SRIOConsumer.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C7EB2122CE1D000262E7 /* SRIOConsumer.m */; }; + FAC7C8192122CE1D000262E7 /* SRIOConsumerPool.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C7ED2122CE1D000262E7 /* SRIOConsumerPool.m */; }; + FAC7C81A2122CE1D000262E7 /* SRProxyConnect.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C7F22122CE1D000262E7 /* SRProxyConnect.m */; }; + FAC7C81B2122CE1D000262E7 /* SRRunLoopThread.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C7F52122CE1D000262E7 /* SRRunLoopThread.m */; }; + FAC7C81C2122CE1D000262E7 /* SRPinningSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C7F82122CE1D000262E7 /* SRPinningSecurityPolicy.m */; }; + FAC7C81D2122CE1D000262E7 /* SRConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C7FA2122CE1D000262E7 /* SRConstants.m */; }; + FAC7C81E2122CE1D000262E7 /* SRError.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C7FD2122CE1D000262E7 /* SRError.m */; }; + FAC7C81F2122CE1D000262E7 /* SRHash.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C7FF2122CE1D000262E7 /* SRHash.m */; }; + FAC7C8202122CE1D000262E7 /* SRHTTPConnectMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C8012122CE1D000262E7 /* SRHTTPConnectMessage.m */; }; + FAC7C8212122CE1D000262E7 /* SRLog.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C8032122CE1D000262E7 /* SRLog.m */; }; + FAC7C8222122CE1D000262E7 /* SRMutex.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C8052122CE1D000262E7 /* SRMutex.m */; }; + FAC7C8232122CE1D000262E7 /* SRRandom.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C8072122CE1D000262E7 /* SRRandom.m */; }; + FAC7C8242122CE1D000262E7 /* SRSIMDHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C8092122CE1D000262E7 /* SRSIMDHelpers.m */; }; + FAC7C8252122CE1D000262E7 /* SRURLUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C80B2122CE1D000262E7 /* SRURLUtilities.m */; settings = {COMPILER_FLAGS = "-Wno-switch"; }; }; + FAC7C8262122CE1D000262E7 /* NSRunLoop+SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C80D2122CE1D000262E7 /* NSRunLoop+SRWebSocket.m */; }; + FAC7C8272122CE1D000262E7 /* NSURLRequest+SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C80F2122CE1D000262E7 /* NSURLRequest+SRWebSocket.m */; }; + FAC7C8282122CE1D000262E7 /* SRSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C8142122CE1D000262E7 /* SRSecurityPolicy.m */; }; + FAC7C8292122CE1D000262E7 /* SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = FAC7C8162122CE1D000262E7 /* SRWebSocket.m */; settings = {COMPILER_FLAGS = "-Wno-deprecated-declarations -Wno-implicit-retain-self"; }; }; + FACCC867211AC281008C87BD /* MyStreamDeckPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = FACCC865211AC281008C87BD /* MyStreamDeckPlugin.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + FA0F7B752105CBC30028CF34 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + FA0F7B772105CBC30028CF34 /* AppleMail */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = AppleMail; sourceTree = BUILT_PRODUCTS_DIR; }; + FA29E46E215E7D2300C9F60C /* ESDConnectionManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ESDConnectionManager.m; sourceTree = ""; }; + FA29E46F215E7D2300C9F60C /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + FA29E470215E7D2300C9F60C /* ESDConnectionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ESDConnectionManager.h; sourceTree = ""; }; + FA29E471215E7D2300C9F60C /* ESDSDKDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ESDSDKDefines.h; sourceTree = ""; }; + FA29E472215E7D2300C9F60C /* ESDEventsProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ESDEventsProtocol.h; sourceTree = ""; }; + FA80591221623A0D00ED7E12 /* ESDUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ESDUtilities.h; sourceTree = ""; }; + FA80591321623A0D00ED7E12 /* ESDUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ESDUtilities.m; sourceTree = ""; }; + FA80591621623C8D00ED7E12 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; }; + FA80591821623C9200ED7E12 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; + FAC7C7E72122CE1D000262E7 /* SRDelegateController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRDelegateController.h; sourceTree = ""; }; + FAC7C7E82122CE1D000262E7 /* SRDelegateController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRDelegateController.m; sourceTree = ""; }; + FAC7C7EA2122CE1D000262E7 /* SRIOConsumer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRIOConsumer.h; sourceTree = ""; }; + FAC7C7EB2122CE1D000262E7 /* SRIOConsumer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRIOConsumer.m; sourceTree = ""; }; + FAC7C7EC2122CE1D000262E7 /* SRIOConsumerPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRIOConsumerPool.h; sourceTree = ""; }; + FAC7C7ED2122CE1D000262E7 /* SRIOConsumerPool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRIOConsumerPool.m; sourceTree = ""; }; + FAC7C7EE2122CE1D000262E7 /* NSRunLoop+SRWebSocketPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSRunLoop+SRWebSocketPrivate.h"; sourceTree = ""; }; + FAC7C7EF2122CE1D000262E7 /* NSURLRequest+SRWebSocketPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURLRequest+SRWebSocketPrivate.h"; sourceTree = ""; }; + FAC7C7F12122CE1D000262E7 /* SRProxyConnect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRProxyConnect.h; sourceTree = ""; }; + FAC7C7F22122CE1D000262E7 /* SRProxyConnect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRProxyConnect.m; sourceTree = ""; }; + FAC7C7F42122CE1D000262E7 /* SRRunLoopThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRRunLoopThread.h; sourceTree = ""; }; + FAC7C7F52122CE1D000262E7 /* SRRunLoopThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRRunLoopThread.m; sourceTree = ""; }; + FAC7C7F72122CE1D000262E7 /* SRPinningSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRPinningSecurityPolicy.h; sourceTree = ""; }; + FAC7C7F82122CE1D000262E7 /* SRPinningSecurityPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRPinningSecurityPolicy.m; sourceTree = ""; }; + FAC7C7F92122CE1D000262E7 /* SRConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRConstants.h; sourceTree = ""; }; + FAC7C7FA2122CE1D000262E7 /* SRConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRConstants.m; sourceTree = ""; }; + FAC7C7FC2122CE1D000262E7 /* SRError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRError.h; sourceTree = ""; }; + FAC7C7FD2122CE1D000262E7 /* SRError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRError.m; sourceTree = ""; }; + FAC7C7FE2122CE1D000262E7 /* SRHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRHash.h; sourceTree = ""; }; + FAC7C7FF2122CE1D000262E7 /* SRHash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRHash.m; sourceTree = ""; }; + FAC7C8002122CE1D000262E7 /* SRHTTPConnectMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRHTTPConnectMessage.h; sourceTree = ""; }; + FAC7C8012122CE1D000262E7 /* SRHTTPConnectMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRHTTPConnectMessage.m; sourceTree = ""; }; + FAC7C8022122CE1D000262E7 /* SRLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRLog.h; sourceTree = ""; }; + FAC7C8032122CE1D000262E7 /* SRLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRLog.m; sourceTree = ""; }; + FAC7C8042122CE1D000262E7 /* SRMutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRMutex.h; sourceTree = ""; }; + FAC7C8052122CE1D000262E7 /* SRMutex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRMutex.m; sourceTree = ""; }; + FAC7C8062122CE1D000262E7 /* SRRandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRRandom.h; sourceTree = ""; }; + FAC7C8072122CE1D000262E7 /* SRRandom.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRRandom.m; sourceTree = ""; }; + FAC7C8082122CE1D000262E7 /* SRSIMDHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRSIMDHelpers.h; sourceTree = ""; }; + FAC7C8092122CE1D000262E7 /* SRSIMDHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRSIMDHelpers.m; sourceTree = ""; }; + FAC7C80A2122CE1D000262E7 /* SRURLUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRURLUtilities.h; sourceTree = ""; }; + FAC7C80B2122CE1D000262E7 /* SRURLUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRURLUtilities.m; sourceTree = ""; }; + FAC7C80C2122CE1D000262E7 /* NSRunLoop+SRWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSRunLoop+SRWebSocket.h"; sourceTree = ""; }; + FAC7C80D2122CE1D000262E7 /* NSRunLoop+SRWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSRunLoop+SRWebSocket.m"; sourceTree = ""; }; + FAC7C80E2122CE1D000262E7 /* NSURLRequest+SRWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURLRequest+SRWebSocket.h"; sourceTree = ""; }; + FAC7C80F2122CE1D000262E7 /* NSURLRequest+SRWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURLRequest+SRWebSocket.m"; sourceTree = ""; }; + FAC7C8112122CE1D000262E7 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + FAC7C8122122CE1D000262E7 /* SocketRocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocketRocket.h; sourceTree = ""; }; + FAC7C8132122CE1D000262E7 /* SRSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRSecurityPolicy.h; sourceTree = ""; }; + FAC7C8142122CE1D000262E7 /* SRSecurityPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRSecurityPolicy.m; sourceTree = ""; }; + FAC7C8152122CE1D000262E7 /* SRWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRWebSocket.h; sourceTree = ""; }; + FAC7C8162122CE1D000262E7 /* SRWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRWebSocket.m; sourceTree = ""; }; + FACCC865211AC281008C87BD /* MyStreamDeckPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MyStreamDeckPlugin.m; sourceTree = ""; }; + FACCC866211AC281008C87BD /* MyStreamDeckPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyStreamDeckPlugin.h; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + FA0F7B742105CBC30028CF34 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + FA80591921623C9200ED7E12 /* AppKit.framework in Frameworks */, + FA80591721623C8D00ED7E12 /* CoreFoundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + FA0F7B6E2105CBC30028CF34 = { + isa = PBXGroup; + children = ( + FACCC866211AC281008C87BD /* MyStreamDeckPlugin.h */, + FACCC865211AC281008C87BD /* MyStreamDeckPlugin.m */, + FA29E46D215E7D2300C9F60C /* Common */, + FAC7C7E42122CE1D000262E7 /* SocketRocket */, + FA0F7B782105CBC30028CF34 /* Products */, + FA80591521623C8D00ED7E12 /* Frameworks */, + ); + sourceTree = ""; + }; + FA0F7B782105CBC30028CF34 /* Products */ = { + isa = PBXGroup; + children = ( + FA0F7B772105CBC30028CF34 /* AppleMail */, + ); + name = Products; + sourceTree = ""; + }; + FA29E46D215E7D2300C9F60C /* Common */ = { + isa = PBXGroup; + children = ( + FA29E470215E7D2300C9F60C /* ESDConnectionManager.h */, + FA29E46E215E7D2300C9F60C /* ESDConnectionManager.m */, + FA29E471215E7D2300C9F60C /* ESDSDKDefines.h */, + FA29E472215E7D2300C9F60C /* ESDEventsProtocol.h */, + FA29E46F215E7D2300C9F60C /* main.m */, + FA80591221623A0D00ED7E12 /* ESDUtilities.h */, + FA80591321623A0D00ED7E12 /* ESDUtilities.m */, + ); + path = Common; + sourceTree = ""; + }; + FA80591521623C8D00ED7E12 /* Frameworks */ = { + isa = PBXGroup; + children = ( + FA80591821623C9200ED7E12 /* AppKit.framework */, + FA80591621623C8D00ED7E12 /* CoreFoundation.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + FAC7C7E42122CE1D000262E7 /* SocketRocket */ = { + isa = PBXGroup; + children = ( + FAC7C7E52122CE1D000262E7 /* Internal */, + FAC7C80C2122CE1D000262E7 /* NSRunLoop+SRWebSocket.h */, + FAC7C80D2122CE1D000262E7 /* NSRunLoop+SRWebSocket.m */, + FAC7C80E2122CE1D000262E7 /* NSURLRequest+SRWebSocket.h */, + FAC7C80F2122CE1D000262E7 /* NSURLRequest+SRWebSocket.m */, + FAC7C8102122CE1D000262E7 /* Resources */, + FAC7C8122122CE1D000262E7 /* SocketRocket.h */, + FAC7C8132122CE1D000262E7 /* SRSecurityPolicy.h */, + FAC7C8142122CE1D000262E7 /* SRSecurityPolicy.m */, + FAC7C8152122CE1D000262E7 /* SRWebSocket.h */, + FAC7C8162122CE1D000262E7 /* SRWebSocket.m */, + ); + name = SocketRocket; + path = Vendor/SocketRocket/SocketRocket; + sourceTree = ""; + }; + FAC7C7E52122CE1D000262E7 /* Internal */ = { + isa = PBXGroup; + children = ( + FAC7C7E62122CE1D000262E7 /* Delegate */, + FAC7C7E92122CE1D000262E7 /* IOConsumer */, + FAC7C7EE2122CE1D000262E7 /* NSRunLoop+SRWebSocketPrivate.h */, + FAC7C7EF2122CE1D000262E7 /* NSURLRequest+SRWebSocketPrivate.h */, + FAC7C7F02122CE1D000262E7 /* Proxy */, + FAC7C7F32122CE1D000262E7 /* RunLoop */, + FAC7C7F62122CE1D000262E7 /* Security */, + FAC7C7F92122CE1D000262E7 /* SRConstants.h */, + FAC7C7FA2122CE1D000262E7 /* SRConstants.m */, + FAC7C7FB2122CE1D000262E7 /* Utilities */, + ); + path = Internal; + sourceTree = ""; + }; + FAC7C7E62122CE1D000262E7 /* Delegate */ = { + isa = PBXGroup; + children = ( + FAC7C7E72122CE1D000262E7 /* SRDelegateController.h */, + FAC7C7E82122CE1D000262E7 /* SRDelegateController.m */, + ); + path = Delegate; + sourceTree = ""; + }; + FAC7C7E92122CE1D000262E7 /* IOConsumer */ = { + isa = PBXGroup; + children = ( + FAC7C7EA2122CE1D000262E7 /* SRIOConsumer.h */, + FAC7C7EB2122CE1D000262E7 /* SRIOConsumer.m */, + FAC7C7EC2122CE1D000262E7 /* SRIOConsumerPool.h */, + FAC7C7ED2122CE1D000262E7 /* SRIOConsumerPool.m */, + ); + path = IOConsumer; + sourceTree = ""; + }; + FAC7C7F02122CE1D000262E7 /* Proxy */ = { + isa = PBXGroup; + children = ( + FAC7C7F12122CE1D000262E7 /* SRProxyConnect.h */, + FAC7C7F22122CE1D000262E7 /* SRProxyConnect.m */, + ); + path = Proxy; + sourceTree = ""; + }; + FAC7C7F32122CE1D000262E7 /* RunLoop */ = { + isa = PBXGroup; + children = ( + FAC7C7F42122CE1D000262E7 /* SRRunLoopThread.h */, + FAC7C7F52122CE1D000262E7 /* SRRunLoopThread.m */, + ); + path = RunLoop; + sourceTree = ""; + }; + FAC7C7F62122CE1D000262E7 /* Security */ = { + isa = PBXGroup; + children = ( + FAC7C7F72122CE1D000262E7 /* SRPinningSecurityPolicy.h */, + FAC7C7F82122CE1D000262E7 /* SRPinningSecurityPolicy.m */, + ); + path = Security; + sourceTree = ""; + }; + FAC7C7FB2122CE1D000262E7 /* Utilities */ = { + isa = PBXGroup; + children = ( + FAC7C7FC2122CE1D000262E7 /* SRError.h */, + FAC7C7FD2122CE1D000262E7 /* SRError.m */, + FAC7C7FE2122CE1D000262E7 /* SRHash.h */, + FAC7C7FF2122CE1D000262E7 /* SRHash.m */, + FAC7C8002122CE1D000262E7 /* SRHTTPConnectMessage.h */, + FAC7C8012122CE1D000262E7 /* SRHTTPConnectMessage.m */, + FAC7C8022122CE1D000262E7 /* SRLog.h */, + FAC7C8032122CE1D000262E7 /* SRLog.m */, + FAC7C8042122CE1D000262E7 /* SRMutex.h */, + FAC7C8052122CE1D000262E7 /* SRMutex.m */, + FAC7C8062122CE1D000262E7 /* SRRandom.h */, + FAC7C8072122CE1D000262E7 /* SRRandom.m */, + FAC7C8082122CE1D000262E7 /* SRSIMDHelpers.h */, + FAC7C8092122CE1D000262E7 /* SRSIMDHelpers.m */, + FAC7C80A2122CE1D000262E7 /* SRURLUtilities.h */, + FAC7C80B2122CE1D000262E7 /* SRURLUtilities.m */, + ); + path = Utilities; + sourceTree = ""; + }; + FAC7C8102122CE1D000262E7 /* Resources */ = { + isa = PBXGroup; + children = ( + FAC7C8112122CE1D000262E7 /* Info.plist */, + ); + path = Resources; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + FA0F7B762105CBC30028CF34 /* AppleMail */ = { + isa = PBXNativeTarget; + buildConfigurationList = FA0F7B7E2105CBC30028CF34 /* Build configuration list for PBXNativeTarget "AppleMail" */; + buildPhases = ( + FA0F7B732105CBC30028CF34 /* Sources */, + FA0F7B742105CBC30028CF34 /* Frameworks */, + FA0F7B752105CBC30028CF34 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = AppleMail; + productName = ObjcPlugin; + productReference = FA0F7B772105CBC30028CF34 /* AppleMail */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + FA0F7B6F2105CBC30028CF34 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1000; + ORGANIZATIONNAME = "Elgato Systems"; + TargetAttributes = { + FA0F7B762105CBC30028CF34 = { + CreatedOnToolsVersion = 10.0; + }; + }; + }; + buildConfigurationList = FA0F7B722105CBC30028CF34 /* Build configuration list for PBXProject "AppleMail" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = FA0F7B6E2105CBC30028CF34; + productRefGroup = FA0F7B782105CBC30028CF34 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + FA0F7B762105CBC30028CF34 /* AppleMail */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + FA0F7B732105CBC30028CF34 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + FAC7C8222122CE1D000262E7 /* SRMutex.m in Sources */, + FA29E473215E7D2300C9F60C /* ESDConnectionManager.m in Sources */, + FAC7C8252122CE1D000262E7 /* SRURLUtilities.m in Sources */, + FAC7C81B2122CE1D000262E7 /* SRRunLoopThread.m in Sources */, + FAC7C8282122CE1D000262E7 /* SRSecurityPolicy.m in Sources */, + FAC7C8262122CE1D000262E7 /* NSRunLoop+SRWebSocket.m in Sources */, + FAC7C8182122CE1D000262E7 /* SRIOConsumer.m in Sources */, + FACCC867211AC281008C87BD /* MyStreamDeckPlugin.m in Sources */, + FAC7C8212122CE1D000262E7 /* SRLog.m in Sources */, + FAC7C8172122CE1D000262E7 /* SRDelegateController.m in Sources */, + FAC7C8202122CE1D000262E7 /* SRHTTPConnectMessage.m in Sources */, + FAC7C8272122CE1D000262E7 /* NSURLRequest+SRWebSocket.m in Sources */, + FAC7C8242122CE1D000262E7 /* SRSIMDHelpers.m in Sources */, + FAC7C81F2122CE1D000262E7 /* SRHash.m in Sources */, + FAC7C81E2122CE1D000262E7 /* SRError.m in Sources */, + FAC7C8192122CE1D000262E7 /* SRIOConsumerPool.m in Sources */, + FA80591421623A0D00ED7E12 /* ESDUtilities.m in Sources */, + FAC7C8292122CE1D000262E7 /* SRWebSocket.m in Sources */, + FAC7C8232122CE1D000262E7 /* SRRandom.m in Sources */, + FAC7C81D2122CE1D000262E7 /* SRConstants.m in Sources */, + FAC7C81A2122CE1D000262E7 /* SRProxyConnect.m in Sources */, + FAC7C81C2122CE1D000262E7 /* SRPinningSecurityPolicy.m in Sources */, + FA29E474215E7D2300C9F60C /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + FA0F7B7C2105CBC30028CF34 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = Vendor/SocketRocket/; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + FA0F7B7D2105CBC30028CF34 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = Vendor/SocketRocket/; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + }; + name = Release; + }; + FA0F7B7F2105CBC30028CF34 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_BUNDLE_IDENTIFIER = com.elgato.applemail; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + FA0F7B802105CBC30028CF34 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_BUNDLE_IDENTIFIER = com.elgato.applemail; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + FA0F7B722105CBC30028CF34 /* Build configuration list for PBXProject "AppleMail" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + FA0F7B7C2105CBC30028CF34 /* Debug */, + FA0F7B7D2105CBC30028CF34 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + FA0F7B7E2105CBC30028CF34 /* Build configuration list for PBXNativeTarget "AppleMail" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + FA0F7B7F2105CBC30028CF34 /* Debug */, + FA0F7B802105CBC30028CF34 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = FA0F7B6F2105CBC30028CF34 /* Project object */; +} diff --git a/Sources/Common/ESDConnectionManager.h b/Sources/Common/ESDConnectionManager.h new file mode 100644 index 0000000..51bec90 --- /dev/null +++ b/Sources/Common/ESDConnectionManager.h @@ -0,0 +1,41 @@ +//============================================================================== +/** +@file ESDConnectionManager.h + +@brief Wrapper to implement the communication with the Stream Deck application + +@copyright (c) 2018, Corsair Memory, Inc. + This source code is licensed under the MIT-style license found in the LICENSE file. + +**/ +//============================================================================== + +#import + +#import "ESDEventsProtocol.h" +#import "ESDSDKDefines.h" + + +NS_ASSUME_NONNULL_BEGIN + + +@interface ESDConnectionManager : NSObject + +- (instancetype)initWithPort:(int)inPort + andPluginUUID:(NSString *)inPluginUUID + andRegisterEvent:(NSString *)inRegisterEvent + andInfo:(NSString *)inInfo + andDelegate:(id)inDelegate; + + +-(void)setTitle:(nullable NSString *)inTitle withContext:(id)inContext withTarget:(ESDSDKTarget)inTarget; +-(void)setImage:(nullable NSString*)inBase64ImageString withContext:(id)inContext withTarget:(ESDSDKTarget)inTarget; +-(void)showAlertForContext:(id)inContext; +-(void)showOKForContext:(id)inContext; +-(void)setSettings:(NSDictionary *)inSettings forContext:(id)inContext; +-(void)setState:(NSNumber *)inState forContext:(id)inContext; + +@end + +NS_ASSUME_NONNULL_END + diff --git a/Sources/Common/ESDConnectionManager.m b/Sources/Common/ESDConnectionManager.m new file mode 100644 index 0000000..589c3c1 --- /dev/null +++ b/Sources/Common/ESDConnectionManager.m @@ -0,0 +1,348 @@ +//============================================================================== +/** +@file ESDConnectionManager.m + +@brief Wrapper to implement the communication with the Stream Deck application + +@copyright (c) 2018, Corsair Memory, Inc. + This source code is licensed under the MIT-style license found in the LICENSE file. + +**/ +//============================================================================== + +#import "ESDConnectionManager.h" + +#import "SRWebSocket.h" + +@interface ESDConnectionManager () + +@property (strong) SRWebSocket *socket; + +@property (assign) int port; +@property (strong) NSString *pluginUUID; +@property (strong) NSString *registerEvent; +@property (strong) NSString *applicationVersion; +@property (strong) NSString *applicationPlatform; +@property (strong) NSString *applicationLanguage; +@property (strong) NSString *devicesInfo; + +@property (weak) id delegate; + +@end + + +@implementation ESDConnectionManager + + +- (instancetype)initWithPort:(int)inPort + andPluginUUID:(NSString *)inPluginUUID + andRegisterEvent:(NSString *)inRegisterEvent + andInfo:(NSString *)inInfo + andDelegate:(id)inDelegate +{ + self = [super init]; + if (self) + { + _port = inPort; + _pluginUUID = inPluginUUID; + _registerEvent = inRegisterEvent; + _delegate = inDelegate; + [_delegate setConnectionManager:self]; + + NSError *error = nil; + NSDictionary *json = [NSJSONSerialization JSONObjectWithData:[inInfo dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&error]; + + NSDictionary *applicationInfo = json[@kESDSDKApplicationInfo]; + _applicationVersion = applicationInfo[@kESDSDKApplicationInfoVersion]; + _applicationPlatform = applicationInfo[@kESDSDKApplicationInfoPlatform]; + _applicationLanguage = applicationInfo[@kESDSDKApplicationInfoLanguage]; + + _devicesInfo = json[@kESDSDKDevicesInfo]; + + NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"ws://localhost:%d", inPort]]]; + self.socket = [[SRWebSocket alloc] initWithURLRequest:urlRequest]; + self.socket.delegate = self; + [self.socket open]; + } + return self; +} + + +#pragma mark - APIs + + +-(void)setTitle:(nullable NSString *)inTitle withContext:(id)inContext withTarget:(ESDSDKTarget)inTarget +{ + NSDictionary *json = nil; + + if(inTitle != NULL) + { + json = @{ + @kESDSDKCommonEvent: @kESDSDKEventSetTitle, + @kESDSDKCommonContext: inContext, + @kESDSDKCommonPayload: @{ + @kESDSDKPayloadTitle: inTitle, + @kESDSDKPayloadTarget: [NSNumber numberWithInt:inTarget] + } + }; + } + else + { + json = @{ + @kESDSDKCommonEvent: @kESDSDKEventSetTitle, + @kESDSDKCommonContext: inContext, + @kESDSDKCommonPayload: @{ + @kESDSDKPayloadTarget: [NSNumber numberWithInt:inTarget] + } + }; + } + + NSError *err = nil; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:&err]; + if (err == nil) + { + NSError *error = nil; + [self.socket sendData:jsonData error:&error]; + if(error != nil) + { + NSLog(@"Failed to change the title due to error %@", error); + } + } +} + +-(void)setImage:(NSString*)inBase64ImageString withContext:(id)inContext withTarget:(ESDSDKTarget)inTarget +{ + NSDictionary *json = @{ + @kESDSDKCommonEvent: @kESDSDKEventSetImage, + @kESDSDKCommonContext: inContext, + @kESDSDKCommonPayload: @{ + @kESDSDKPayloadImage: inBase64ImageString, + @kESDSDKPayloadTarget: [NSNumber numberWithInt:inTarget] + } + }; + + NSError *err = nil; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:&err]; + if (err == nil) + { + NSError *error = nil; + [self.socket sendData:jsonData error:&error]; + if(error != nil) + { + NSLog(@"Failed to change the image due to error %@", error); + } + } +} + +-(void)showAlertForContext:(id)inContext +{ + NSDictionary *json = @{ + @kESDSDKCommonEvent: @kESDSDKEventShowAlert, + @kESDSDKCommonContext: inContext, + }; + + NSError *err = nil; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:&err]; + if (err == nil) + { + NSError *error = nil; + [self.socket sendData:jsonData error:&error]; + if(error != nil) + { + NSLog(@"Failed to show the alert due to error %@", error); + } + } +} + +-(void)showOKForContext:(id)inContext +{ + NSDictionary *json = @{ + @kESDSDKCommonEvent: @kESDSDKEventShowOK, + @kESDSDKCommonContext: inContext, + }; + + NSError *err = nil; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:&err]; + if (err == nil) + { + NSError *error = nil; + [self.socket sendData:jsonData error:&error]; + if(error != nil) + { + NSLog(@"Failed to show OK due to error %@", error); + } + } +} + +-(void)setSettings:(NSDictionary *)inSettings forContext:(id)inContext +{ + NSDictionary *json = @{ + @kESDSDKCommonEvent: @kESDSDKEventSetSettings, + @kESDSDKCommonContext: inContext, + @kESDSDKCommonPayload: inSettings + }; + + NSError *err = nil; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:json options:0 error:&err]; + if (err == nil) + { + NSError *error = nil; + [self.socket sendData:jsonData error:&error]; + if(error != nil) + { + NSLog(@"Failed to change the settings due to error %@", error); + } + } +} + +-(void)setState:(NSNumber *)inState forContext:(id)inContext +{ + if(inState != NULL) + { + NSDictionary *json = @{ + @kESDSDKCommonEvent: @kESDSDKEventSetState, + @kESDSDKCommonContext: inContext, + @kESDSDKCommonPayload: @{ + @kESDSDKPayloadState: inState + } + }; + + NSError *err = nil; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:&err]; + if (err == nil) + { + NSError *error = nil; + [self.socket sendData:jsonData error:&error]; + if(error != nil) + { + NSLog(@"Failed to change the state due to error %@", error); + } + } + } +} + + +#pragma mark - WebSocket events + +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message +{ + @try + { + NSError *error = nil; + NSDictionary *json = nil; + if([message isKindOfClass:[NSString class]]) + { + json = [NSJSONSerialization JSONObjectWithData:[message dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&error]; + } + else if([message isKindOfClass:[NSData class]]) + { + json = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&error]; + } + + NSString *event = json[@kESDSDKCommonEvent]; + id context = json[@kESDSDKCommonContext]; + NSString *action = json[@kESDSDKCommonAction]; + NSDictionary *payload = json[@kESDSDKCommonPayload]; + NSString *deviceID = json[@kESDSDKCommonDevice]; + + if([event isEqualToString:@kESDSDKEventKeyDown]) + { + if([self.delegate respondsToSelector:@selector(keyDownForAction:withContext:withPayload:forDevice:)]) + { + [self.delegate keyDownForAction:action withContext:context withPayload:payload forDevice:deviceID]; + } + } + else if([event isEqualToString:@kESDSDKEventKeyUp]) + { + if([self.delegate respondsToSelector:@selector(keyUpForAction:withContext:withPayload:forDevice:)]) + { + [self.delegate keyUpForAction:action withContext:context withPayload:payload forDevice:deviceID]; + } + } + else if([event isEqualToString:@kESDSDKEventWillAppear]) + { + if([self.delegate respondsToSelector:@selector(willAppearForAction:withContext:withPayload:forDevice:)]) + { + [self.delegate willAppearForAction:action withContext:context withPayload:payload forDevice:deviceID]; + } + } + else if([event isEqualToString:@kESDSDKEventWillDisappear]) + { + if([self.delegate respondsToSelector:@selector(willDisappearForAction:withContext:withPayload:forDevice:)]) + { + [self.delegate willDisappearForAction:action withContext:context withPayload:payload forDevice:deviceID]; + } + } + else if([event isEqualToString:@kESDSDKEventDeviceDidConnect]) + { + if([self.delegate respondsToSelector:@selector(deviceDidConnect:withDeviceInfo:)]) + { + NSDictionary *deviceInfo = json[@kESDSDKCommonDeviceInfo]; + if(deviceID != nil) + { + [self.delegate deviceDidConnect:deviceID withDeviceInfo:deviceInfo]; + } + } + } + else if([event isEqualToString:@kESDSDKEventDeviceDidDisconnect]) + { + if([self.delegate respondsToSelector:@selector(deviceDidDisconnect:)]) + { + [self.delegate deviceDidDisconnect:deviceID]; + } + } + else if([event isEqualToString:@kESDSDKEventApplicationDidLaunch]) + { + if([self.delegate respondsToSelector:@selector(applicationDidLaunch:)]) + { + [self.delegate applicationDidLaunch:payload]; + } + } + else if([event isEqualToString:@kESDSDKEventApplicationDidTerminate]) + { + if([self.delegate respondsToSelector:@selector(applicationDidTerminate:)]) + { + [self.delegate applicationDidTerminate:payload]; + } + } + } + @catch(...) + { + NSLog(@"Failed to parse the JSON data: %@", message); + } +} + +- (void)webSocketDidOpen:(SRWebSocket *)webSocket +{ + NSDictionary *registerJson = @{ + @kESDSDKCommonEvent: self.registerEvent, + @kESDSDKRegisterUUID: self.pluginUUID }; + + NSError *err = nil; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:registerJson options:NSJSONWritingPrettyPrinted error:&err]; + if (err == nil) + { + NSError *error = nil; + [self.socket sendData:jsonData error:&error]; + if(error != nil) + { + NSLog(@"Failed to register the plugin due to error %@", error); + } + } +} + +- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error +{ + NSLog(@"The socket could not be opened due to the error %@", error); +} + +- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean +{ + NSLog(@"Websocket closed with reason: %@", reason); + + // The socket has been closed so we just quit + exit(0); +} + + +@end diff --git a/Sources/Common/ESDEventsProtocol.h b/Sources/Common/ESDEventsProtocol.h new file mode 100644 index 0000000..dce5238 --- /dev/null +++ b/Sources/Common/ESDEventsProtocol.h @@ -0,0 +1,44 @@ +//============================================================================== +/** +@file ESDEventsProtocol.h + +@brief Protocol used for the communication with the Stream Deck application + +@copyright (c) 2018, Corsair Memory, Inc. + This source code is licensed under the MIT-style license found in the LICENSE file. + +**/ +//============================================================================== + +#import + +@class ESDConnectionManager; + +NS_ASSUME_NONNULL_BEGIN + +@protocol ESDEventsProtocol + +@required + +- (void)setConnectionManager:(ESDConnectionManager *)connectionManager; + + +@optional + +- (void)keyDownForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID; +- (void)keyUpForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID; + +- (void)willAppearForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID; +- (void)willDisappearForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID; + +- (void)deviceDidConnect:(NSString *)deviceID withDeviceInfo:(NSDictionary *)deviceInfo; +- (void)deviceDidDisconnect:(NSString *)deviceID; + +- (void)applicationDidLaunch:(NSDictionary *)applicationInfo; +- (void)applicationDidTerminate:(NSDictionary *)applicationInfo; + +@end + + +NS_ASSUME_NONNULL_END + diff --git a/Sources/Common/ESDSDKDefines.h b/Sources/Common/ESDSDKDefines.h new file mode 100644 index 0000000..d36c130 --- /dev/null +++ b/Sources/Common/ESDSDKDefines.h @@ -0,0 +1,152 @@ +//============================================================================== +/** +@file ESDSDKDefines.h + +@brief Defines used for the Stream Deck communication + +@copyright (c) 2018, Corsair Memory, Inc. + This source code is licensed under the MIT-style license found in the LICENSE file. + +**/ +//============================================================================== + +#pragma once + + +// +// Common base-interface +// + +#define kESDSDKCommonAction "action" +#define kESDSDKCommonEvent "event" +#define kESDSDKCommonContext "context" +#define kESDSDKCommonPayload "payload" +#define kESDSDKCommonDevice "device" +#define kESDSDKCommonDeviceInfo "deviceInfo" + + +// +// Events +// + +#define kESDSDKEventKeyDown "keyDown" +#define kESDSDKEventKeyUp "keyUp" +#define kESDSDKEventWillAppear "willAppear" +#define kESDSDKEventWillDisappear "willDisappear" +#define kESDSDKEventDeviceDidConnect "deviceDidConnect" +#define kESDSDKEventDeviceDidDisconnect "deviceDidDisconnect" +#define kESDSDKEventApplicationDidLaunch "applicationDidLaunch" +#define kESDSDKEventApplicationDidTerminate "applicationDidTerminate" +#define kESDSDKEventTitleParametersDidChange "titleParametersDidChange" + + +// +// Functions +// + +#define kESDSDKEventSetTitle "setTitle" +#define kESDSDKEventSetImage "setImage" +#define kESDSDKEventShowAlert "showAlert" +#define kESDSDKEventShowOK "showOk" +#define kESDSDKEventSetSettings "setSettings" +#define kESDSDKEventSetState "setState" +#define kESDSDKEventSwitchToProfile "switchToProfile" +#define kESDSDKEventSendToPropertyInspector "sendToPropertyInspector" +#define kESDSDKEventSendToPlugin "sendToPlugin" +#define kESDSDKEventOpenURL "openUrl" + + +// +// Payloads +// + +#define kESDSDKPayloadSettings "settings" +#define kESDSDKPayloadCoordinates "coordinates" +#define kESDSDKPayloadState "state" +#define kESDSDKPayloadUserDesiredState "userDesiredState" +#define kESDSDKPayloadTitle "title" +#define kESDSDKPayloadTitleParameters "titleParameters" +#define kESDSDKPayloadImage "image" +#define kESDSDKPayloadURL "url" +#define kESDSDKPayloadTarget "target" +#define kESDSDKPayloadProfile "profile" +#define kESDSDKPayloadApplication "application" +#define kESDSDKPayloadIsInMultiAction "isInMultiAction" + +#define kESDSDKPayloadCoordinatesColumn "column" +#define kESDSDKPayloadCoordinatesRow "row" + +// +// Device Info +// + +#define kESDSDKDeviceInfoID "id" +#define kESDSDKDeviceInfoType "type" +#define kESDSDKDeviceInfoSize "size" + +#define kESDSDKDeviceInfoSizeColumns "columns" +#define kESDSDKDeviceInfoSizeRows "rows" + + +// +// Title Parameters +// + +#define kESDSDKTitleParametersShowTitle "showTitle" +#define kESDSDKTitleParametersTitleColor "titleColor" +#define kESDSDKTitleParametersTitleAlignment "titleAlignment" +#define kESDSDKTitleParametersFontFamily "fontFamily" +#define kESDSDKTitleParametersFontSize "fontSize" +#define kESDSDKTitleParametersCustomFontSize "customFontSize" +#define kESDSDKTitleParametersFontStyle "fontStyle" +#define kESDSDKTitleParametersFontUnderline "fontUnderline" + + +// +// Connection +// + +#define kESDSDKConnectSocketFunction "connectSocket" +#define kESDSDKRegisterPlugin "registerPlugin" +#define kESDSDKRegisterPropertyInspector "registerPropertyInspector" +#define kESDSDKPortParameter "-port" +#define kESDSDKPluginUUIDParameter "-pluginUUID" +#define kESDSDKRegisterEventParameter "-registerEvent" +#define kESDSDKInfoParameter "-info" +#define kESDSDKRegisterUUID "uuid" + +#define kESDSDKApplicationInfo "application" +#define kESDSDKDevicesInfo "devices" +#define kESDSDKColorsInfo "colors" + +#define kESDSDKApplicationInfoVersion "version" +#define kESDSDKApplicationInfoLanguage "language" +#define kESDSDKApplicationInfoPlatform "platform" + +#define kESDSDKApplicationInfoPlatformMac "mac" +#define kESDSDKApplicationInfoPlatformWindows "windows" + +#define kESDSDKColorsInfoHighlightColor "highlightColor" +#define kESDSDKColorsInfoMouseDownColor "mouseDownColor" +#define kESDSDKColorsInfoDisabledColor "disabledColor" +#define kESDSDKColorsInfoButtonPressedTextColor "buttonPressedTextColor" +#define kESDSDKColorsInfoButtonPressedBackgroundColor "buttonPressedBackgroundColor" +#define kESDSDKColorsInfoButtonMouseOverBackgroundColor "buttonMouseOverBackgroundColor" +#define kESDSDKColorsInfoButtonPressedBorderColor "buttonPressedBorderColor" + + +typedef int ESDSDKTarget; +enum +{ + kESDSDKTarget_HardwareAndSoftware = 0, + kESDSDKTarget_HardwareOnly = 1, + kESDSDKTarget_SoftwareOnly = 2 +}; + +typedef int ESDSDKDeviceType; +enum +{ + kESDSDKDeviceType_StreamDeck = 0, + kESDSDKDeviceType_StreamDeckMini = 1 +}; + diff --git a/Sources/Common/ESDUtilities.h b/Sources/Common/ESDUtilities.h new file mode 100644 index 0000000..bc2a217 --- /dev/null +++ b/Sources/Common/ESDUtilities.h @@ -0,0 +1,28 @@ +//============================================================================== +/** +@file ESDUtilities.h + +@brief Various filesystem and other utility functions + +@copyright (c) 2018, Corsair Memory, Inc. + This source code is licensed under the MIT-style license found in the LICENSE file. + +**/ +//============================================================================== + +#pragma once + +#import + + +NS_ASSUME_NONNULL_BEGIN + + +@interface ESDUtilities : NSObject + ++(nullable NSString *)pluginPath; + + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Common/ESDUtilities.m b/Sources/Common/ESDUtilities.m new file mode 100644 index 0000000..5bd5b56 --- /dev/null +++ b/Sources/Common/ESDUtilities.m @@ -0,0 +1,87 @@ +//============================================================================== +/** +@file ESDUtilities.m + +@brief Various filesystem and other utility functions + +@copyright (c) 2018, Corsair Memory, Inc. + This source code is licensed under the MIT-style license found in the LICENSE file. + +**/ +//============================================================================== + +#include "ESDUtilities.h" + + +@implementation ESDUtilities + + ++(nullable NSString *)pluginPath +{ + static NSString *sPluginPath = nil; + + if(sPluginPath == nil) + { + CFBundleRef bundleRef = CFBundleGetMainBundle(); + if(bundleRef != NULL) + { + CFURLRef executableURL = CFBundleCopyExecutableURL(bundleRef); + if(executableURL != NULL) + { + CFURLRef checkURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, executableURL); + while(checkURL != NULL) + { + CFStringRef lastPathComponent = CFURLCopyLastPathComponent(checkURL); + if(lastPathComponent == NULL || (CFStringCompare(lastPathComponent, CFSTR("/"), 0) == kCFCompareEqualTo) || (CFStringCompare(lastPathComponent, CFSTR(".."), 0) == kCFCompareEqualTo)) + { + if(lastPathComponent != NULL) + { + CFRelease(lastPathComponent); + } + + CFRelease(checkURL); + checkURL = NULL; + break; + } + + CFRelease(lastPathComponent); + + CFStringRef pathExtension = CFURLCopyPathExtension(checkURL); + if(pathExtension != NULL) + { + if(CFStringCompare(pathExtension, CFSTR("sdPlugin"), 0) == kCFCompareEqualTo) + { + CFStringRef path = CFURLCopyFileSystemPath(checkURL, kCFURLPOSIXPathStyle); + if(path != NULL) + { + sPluginPath = [[NSString alloc] initWithString:(__bridge NSString *)(path)]; + CFRelease(path); + } + } + + CFRelease(pathExtension); + } + + CFURLRef previousURL = checkURL; + checkURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, previousURL); + CFRelease(previousURL); + + if(sPluginPath != nil) + { + CFRelease(checkURL); + checkURL = NULL; + break; + } + } + + CFRelease(executableURL); + } + } + } + + return sPluginPath; +} + + +@end + diff --git a/Sources/Common/main.m b/Sources/Common/main.m new file mode 100644 index 0000000..93f75bf --- /dev/null +++ b/Sources/Common/main.m @@ -0,0 +1,91 @@ +//============================================================================== +/** +@file main.m + +@brief Parse the arg parameters and start the plugin + +@copyright (c) 2018, Corsair Memory, Inc. + This source code is licensed under the MIT-style license found in the LICENSE file. + +**/ +//============================================================================== + +#import +#import "ESDConnectionManager.h" +#import "ESDSDKDefines.h" + +#import "MyStreamDeckPlugin.h" + +int main(int argc, const char * argv[]) +{ + @autoreleasepool + { + if (argc != 9) + { + fprintf(stderr, "Invalid number of parameters %d instead of 9", argc); + return 1; + } + + int port = 0; + NSString *pluginUUID = nil; + NSString *registerEvent = nil; + NSString *info = nil; + + for(int argumentIndex = 0 ; argumentIndex < 4 ; argumentIndex++) + { + NSString *parameter = [NSString stringWithUTF8String:argv[1 + 2 * argumentIndex]]; + NSString *value = [NSString stringWithUTF8String:argv[1 + 2 * argumentIndex + 1]]; + + if ([parameter isEqualToString:@kESDSDKPortParameter]) + { + port = [value intValue]; + } + else if ([parameter isEqualToString:@kESDSDKPluginUUIDParameter]) + { + pluginUUID = value; + } + else if ([parameter isEqualToString:@kESDSDKRegisterEventParameter]) + { + registerEvent = value; + } + else if ([parameter isEqualToString:@kESDSDKInfoParameter]) + { + info = value; + } + } + + if(port == 0) + { + fprintf(stderr, "Invalid port number"); + return 1; + } + + if([pluginUUID length] <= 0) + { + fprintf(stderr, "Invalid plugin UUID"); + return 1; + } + + if([registerEvent length] <= 0) + { + fprintf(stderr, "Invalid registerEvent"); + return 1; + } + + // Create MyStreamDeckPlugin + MyStreamDeckPlugin *eventsManager = [[MyStreamDeckPlugin alloc] init]; + + // Create the connection manager + ESDConnectionManager * __unused connectionManager = [[ESDConnectionManager alloc] initWithPort:port andPluginUUID:pluginUUID andRegisterEvent:registerEvent andInfo:info andDelegate:eventsManager]; + + + // Start the runloop + BOOL keepRunning = YES; + while(keepRunning && [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) + { + + } + } + + return 0; +} diff --git a/Sources/MyStreamDeckPlugin.h b/Sources/MyStreamDeckPlugin.h new file mode 100644 index 0000000..a96c7cf --- /dev/null +++ b/Sources/MyStreamDeckPlugin.h @@ -0,0 +1,39 @@ +//============================================================================== +/** +@file MyStreamDeckPlugin.h + +@brief A Stream Deck plugin displaying the number of unread emails in Apple's Mail + +@copyright (c) 2018, Corsair Memory, Inc. + This source code is licensed under the MIT-style license found in the LICENSE file. + +**/ +//============================================================================== + +#import +#import "ESDEventsProtocol.h" + +@class ESDConnectionManager; + + +NS_ASSUME_NONNULL_BEGIN + +@interface MyStreamDeckPlugin : NSObject + +@property (weak) ESDConnectionManager *connectionManager; + +- (void)keyDownForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID; +- (void)keyUpForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID; +- (void)willAppearForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID; +- (void)willDisappearForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID; + +- (void)deviceDidConnect:(NSString *)deviceID withDeviceInfo:(NSDictionary *)deviceInfo; +- (void)deviceDidDisconnect:(NSString *)deviceID; + +- (void)applicationDidLaunch:(NSDictionary *)applicationInfo; +- (void)applicationDidTerminate:(NSDictionary *)applicationInfo; + +@end + +NS_ASSUME_NONNULL_END + diff --git a/Sources/MyStreamDeckPlugin.m b/Sources/MyStreamDeckPlugin.m new file mode 100644 index 0000000..97f90f7 --- /dev/null +++ b/Sources/MyStreamDeckPlugin.m @@ -0,0 +1,307 @@ +//============================================================================== +/** +@file MyStreamDeckPlugin.m + +@brief A Stream Deck plugin displaying the number of unread emails in Apple's Mail + +@copyright (c) 2018, Corsair Memory, Inc. + This source code is licensed under the MIT-style license found in the LICENSE file. + +**/ +//============================================================================== + +#import "MyStreamDeckPlugin.h" + +#import "ESDSDKDefines.h" +#import "ESDConnectionManager.h" +#import "ESDUtilities.h" +#import + + +// Refresh the unread count every 60s +#define REFRESH_UNREAD_COUNT_TIME_INTERVAL 60.0 + + +// Size of the images +#define IMAGE_SIZE 144 + + + +// MARK: - Utility methods + + +// +// Utility function to get the fullpath of an resource in the bundle +// +static NSString * GetResourcePath(NSString *inFilename) +{ + NSString *outPath = nil; + + if([inFilename length] > 0) + { + NSString * bundlePath = [ESDUtilities pluginPath]; + if(bundlePath != nil) + { + outPath = [bundlePath stringByAppendingPathComponent:inFilename]; + } + } + + return outPath; +} + + +// +// Utility function to create a CGContextRef +// +static CGContextRef CreateBitmapContext(CGSize inSize) +{ + CGFloat bitmapBytesPerRow = inSize.width * 4; + CGFloat bitmapByteCount = (bitmapBytesPerRow * inSize.height); + + void *bitmapData = calloc(bitmapByteCount, 1); + if(bitmapData == NULL) + { + return NULL; + } + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGContextRef context = CGBitmapContextCreate(bitmapData, inSize.width, inSize.height, 8, bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); + if(context == NULL) + { + CGColorSpaceRelease(colorSpace); + free(bitmapData); + return NULL; + } + else + { + CGColorSpaceRelease(colorSpace); + return context; + } +} + +// +// Utility method that takes the path of an image and create a base64 encoded string +// +static NSString * CreateBase64EncodedString(NSString *inImagePath) +{ + NSString *outBase64PNG = nil; + + NSImage* image = [[NSImage alloc] initWithContentsOfFile:inImagePath]; + if(image != nil) + { + // Find the best CGImageRef + CGSize iconSize = CGSizeMake(IMAGE_SIZE, IMAGE_SIZE); + NSRect theRect = NSMakeRect(0, 0, iconSize.width, iconSize.height); + CGImageRef imageRef = [image CGImageForProposedRect:&theRect context:NULL hints:nil]; + if(imageRef != NULL) + { + // Create a CGContext + CGContextRef context = CreateBitmapContext(iconSize); + if(context != NULL) + { + // Draw the Mail.app icon + CGContextDrawImage(context, theRect, imageRef); + + // Generate the final image + CGImageRef completeImage = CGBitmapContextCreateImage(context); + if(completeImage != NULL) + { + // Export the image to PNG + CFMutableDataRef pngData = CFDataCreateMutable(kCFAllocatorDefault, 0); + if(pngData != NULL) + { + CGImageDestinationRef destinationRef = CGImageDestinationCreateWithData(pngData, kUTTypePNG, 1, NULL); + if (destinationRef != NULL) + { + CGImageDestinationAddImage(destinationRef, completeImage, nil); + if (CGImageDestinationFinalize(destinationRef)) + { + NSString *base64PNG = [(__bridge NSData *)pngData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn]; + if([base64PNG length] > 0) + { + outBase64PNG = [NSString stringWithFormat:@"data:image/png;base64,%@\">", base64PNG]; + } + } + + CFRelease(destinationRef); + } + + CFRelease(pngData); + } + + CFRelease(completeImage); + } + + CFRelease(context); + } + } + } + + return outBase64PNG; +} + + +// MARK: - MyStreamDeckPlugin + +@interface MyStreamDeckPlugin () + +// Tells us if Apple Mail is running +@property (assign) BOOL isAppleMailRunning; + +// A timer fired each minute to update the number of unread email from Apple's Mail +@property (strong) NSTimer *refreshTimer; + +// The list of visible contexts +@property (strong) NSMutableArray *knownContexts; + +// The Mail icon encoded in base64 +@property (strong) NSString *base64MailIconString; + +// The Mail icon with a badge encoded in base64 +@property (strong) NSString *base64MailBadgeIconString; + +@end + + +@implementation MyStreamDeckPlugin + + + +// MARK: - Setup the instance variables if needed + +- (void)setupIfNeeded +{ + // Create the array of known contexts + if(_knownContexts == nil) + { + _knownContexts = [[NSMutableArray alloc] init]; + } + + // Create a timer to repetivily update the actions + if(_refreshTimer == nil) + { + _refreshTimer = [NSTimer scheduledTimerWithTimeInterval:REFRESH_UNREAD_COUNT_TIME_INTERVAL target:self selector:@selector(refreshUnreadCount) userInfo:nil repeats:YES]; + } + + if(_base64MailIconString == nil) + { + _base64MailIconString = CreateBase64EncodedString(GetResourcePath(@"MailIcon.png")); + } + + if(_base64MailBadgeIconString == nil) + { + _base64MailBadgeIconString = CreateBase64EncodedString(GetResourcePath(@"MailBadgeIcon.png")); + } +} + + +// MARK: - Refresh all actions + +- (void)refreshUnreadCount +{ + if(!self.isAppleMailRunning) + { + return; + } + + // Execute the NumberOfUnreadMails.scpt Applescript tp retrieve the number of unread emails + int numberOfUnreadEmails = 0; + NSURL* url = [NSURL fileURLWithPath:GetResourcePath(@"NumberOfUnreadMails.scpt")]; + + NSDictionary *errors = nil; + NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors]; + if(appleScript != nil) + { + NSAppleEventDescriptor *eventDescriptor = [appleScript executeAndReturnError:&errors]; + if(eventDescriptor != nil && [eventDescriptor descriptorType] != kAENullEvent) + { + numberOfUnreadEmails = (int)[eventDescriptor int32Value]; + } + } + + // Update each known context with the new value + for(NSString *context in self.knownContexts) + { + if(numberOfUnreadEmails >= 0) + { + [self.connectionManager setImage:self.base64MailBadgeIconString withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware]; + [self.connectionManager setTitle:[NSString stringWithFormat:@"%d", numberOfUnreadEmails] withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware]; + } + else + { + [self.connectionManager setImage:self.base64MailIconString withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware]; + [self.connectionManager showAlertForContext:context]; + } + } +} + + +// MARK: - Events handler + + +- (void)keyDownForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID +{ + // On key press, open the Mail.app application + NSURL* url = [NSURL fileURLWithPath:GetResourcePath(@"OpenMail.scpt")]; + + NSDictionary *errors = nil; + NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors]; + if(appleScript != nil) + { + [appleScript executeAndReturnError:&errors]; + } +} + +- (void)keyUpForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID +{ + // Nothing to do +} + +- (void)willAppearForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID +{ + // Set up the instance variables if needed + [self setupIfNeeded]; + + // Add the context to the list of known contexts + [self.knownContexts addObject:context]; + + // Explicitely refresh the number of unread emails + [self refreshUnreadCount]; +} + +- (void)willDisappearForAction:(NSString *)action withContext:(id)context withPayload:(NSDictionary *)payload forDevice:(NSString *)deviceID +{ + // Remove the context from the list of known contexts + [self.knownContexts removeObject:context]; +} + +- (void)deviceDidConnect:(NSString *)deviceID withDeviceInfo:(NSDictionary *)deviceInfo +{ + // Nothing to do +} + +- (void)deviceDidDisconnect:(NSString *)deviceID +{ + // Nothing to do +} + +- (void)applicationDidLaunch:(NSDictionary *)applicationInfo +{ + if([applicationInfo[@kESDSDKPayloadApplication] isEqualToString:@"com.apple.mail"]) + { + self.isAppleMailRunning = YES; + + // Explicitely refresh the number of unread emails + [self refreshUnreadCount]; + } +} + +- (void)applicationDidTerminate:(NSDictionary *)applicationInfo +{ + if([applicationInfo[@kESDSDKPayloadApplication] isEqualToString:@"com.apple.mail"]) + { + self.isAppleMailRunning = NO; + } +} + +@end diff --git a/Sources/Vendor/SocketRocket/CONTRIBUTING.md b/Sources/Vendor/SocketRocket/CONTRIBUTING.md new file mode 100755 index 0000000..1fa59e7 --- /dev/null +++ b/Sources/Vendor/SocketRocket/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# Contributing to SocketRocket +We want to make contributing to this project as easy and transparent as possible. + +## Pull Requests +We actively welcome your pull requests. + +1. Fork the repo and create your branch from `master`. +2. If you've added code that should be tested, add tests. +3. If you've changed APIs, update the documentation. +4. Ensure the test suite passes. +5. Make sure your code lints. +6. If you haven't already, complete the Contributor License Agreement ("CLA"). + +## Contributor License Agreement ("CLA") +In order to accept your pull request, we need you to submit a CLA. +You only need to do this once to work on any of Facebook's open source projects. + +Complete your CLA here: + +## Issues +We use GitHub issues to track public bugs. Please ensure your description is +clear and has sufficient instructions to be able to reproduce the issue. + +Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe +disclosure of security bugs. In those cases, please go through the process +outlined on that page and do not file a public issue. + +## Coding Style +* Most importantly, match the existing code style as much as possible. +* Try to keep lines under 140 characters, if possible. + +## License +By contributing to SocketRocket, you agree that your contributions will be licensed under its BSD license. \ No newline at end of file diff --git a/Sources/Vendor/SocketRocket/Configurations/SocketRocket-iOS-Dynamic.xcconfig b/Sources/Vendor/SocketRocket/Configurations/SocketRocket-iOS-Dynamic.xcconfig new file mode 100755 index 0000000..526b259 --- /dev/null +++ b/Sources/Vendor/SocketRocket/Configurations/SocketRocket-iOS-Dynamic.xcconfig @@ -0,0 +1,17 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#include "Shared/Platform/iOS.xcconfig" +#include "Shared/Product/DynamicFramework.xcconfig" + +PRODUCT_NAME = SocketRocket +PRODUCT_BUNDLE_IDENTIFIER = com.facebook.socketrocket.ios +IPHONEOS_DEPLOYMENT_TARGET = 8.0 + +INFOPLIST_FILE = $(SRCROOT)/SocketRocket/Resources/Info.plist diff --git a/Sources/Vendor/SocketRocket/Configurations/SocketRocket-iOS.xcconfig b/Sources/Vendor/SocketRocket/Configurations/SocketRocket-iOS.xcconfig new file mode 100755 index 0000000..d4af81d --- /dev/null +++ b/Sources/Vendor/SocketRocket/Configurations/SocketRocket-iOS.xcconfig @@ -0,0 +1,20 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#include "Shared/Platform/iOS.xcconfig" +#include "Shared/Product/StaticFramework.xcconfig" + +PRODUCT_NAME = SocketRocket +PRODUCT_BUNDLE_IDENTIFIER = com.facebook.socketrocket.ios +IPHONEOS_DEPLOYMENT_TARGET = 6.0 + +INFOPLIST_FILE = $(SRCROOT)/SocketRocket/Resources/Info.plist + +OTHER_CFLAGS[sdk=iphoneos9.*] = $(inherited) -fembed-bitcode +OTHER_LDFLAGS = $(inherited) -Licucore diff --git a/Sources/Vendor/SocketRocket/Configurations/SocketRocket-macOS.xcconfig b/Sources/Vendor/SocketRocket/Configurations/SocketRocket-macOS.xcconfig new file mode 100755 index 0000000..7308c45 --- /dev/null +++ b/Sources/Vendor/SocketRocket/Configurations/SocketRocket-macOS.xcconfig @@ -0,0 +1,17 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#include "Shared/Platform/macOS.xcconfig" +#include "Shared/Product/DynamicFramework.xcconfig" + +PRODUCT_NAME = SocketRocket +PRODUCT_BUNDLE_IDENTIFIER = com.facebook.socketrocket.macos +MACOSX_DEPLOYMENT_TARGET = 10.8 + +INFOPLIST_FILE = $(SRCROOT)/SocketRocket/Resources/Info.plist diff --git a/Sources/Vendor/SocketRocket/Configurations/SocketRocket-tvOS.xcconfig b/Sources/Vendor/SocketRocket/Configurations/SocketRocket-tvOS.xcconfig new file mode 100755 index 0000000..12e64bf --- /dev/null +++ b/Sources/Vendor/SocketRocket/Configurations/SocketRocket-tvOS.xcconfig @@ -0,0 +1,16 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#include "Shared/Platform/tvOS.xcconfig" +#include "Shared/Product/DynamicFramework.xcconfig" + +PRODUCT_NAME = SocketRocket +PRODUCT_BUNDLE_IDENTIFIER = com.facebook.socketrocket.tvos + +INFOPLIST_FILE = $(SRCROOT)/SocketRocket/Resources/Info.plist diff --git a/Sources/Vendor/SocketRocket/Configurations/SocketRocketTests-iOS.xcconfig b/Sources/Vendor/SocketRocket/Configurations/SocketRocketTests-iOS.xcconfig new file mode 100755 index 0000000..7f02fc2 --- /dev/null +++ b/Sources/Vendor/SocketRocket/Configurations/SocketRocketTests-iOS.xcconfig @@ -0,0 +1,19 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#include "Shared/Platform/iOS.xcconfig" +#include "Shared/Product/LogicTests.xcconfig" + +PRODUCT_NAME = SocketRocketTests-iOS +PRODUCT_MODULE_NAME = SocketRocketTests +PRODUCT_BUNDLE_IDENTIFIER = com.facebook.socketrocket.tests.ios + +IPHONEOS_DEPLOYMENT_TARGET = 7.0 + +INFOPLIST_FILE = $(SRCROOT)/Tests/Resources/Info.plist diff --git a/Sources/Vendor/SocketRocket/Configurations/TestChat-iOS.xcconfig b/Sources/Vendor/SocketRocket/Configurations/TestChat-iOS.xcconfig new file mode 100755 index 0000000..a12622f --- /dev/null +++ b/Sources/Vendor/SocketRocket/Configurations/TestChat-iOS.xcconfig @@ -0,0 +1,19 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#include "Shared/Platform/iOS.xcconfig" +#include "Shared/Product/Application.xcconfig" + +PRODUCT_NAME = TestChat +PRODUCT_MODULE_NAME = TestChat +PRODUCT_BUNDLE_IDENTIFIER = com.facebook.socketrocket.testchat + +IPHONEOS_DEPLOYMENT_TARGET = 8.0 + +INFOPLIST_FILE = $(SRCROOT)/TestChat/TestChat-Info.plist diff --git a/Sources/Vendor/SocketRocket/Gemfile b/Sources/Vendor/SocketRocket/Gemfile new file mode 100755 index 0000000..43c41f9 --- /dev/null +++ b/Sources/Vendor/SocketRocket/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'cocoapods' +gem 'xcpretty' diff --git a/Sources/Vendor/SocketRocket/LICENSE b/Sources/Vendor/SocketRocket/LICENSE new file mode 100755 index 0000000..032b206 --- /dev/null +++ b/Sources/Vendor/SocketRocket/LICENSE @@ -0,0 +1,30 @@ +BSD License + +For SocketRocket software + +Copyright (c) 2016-present, Facebook, Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name Facebook nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/Sources/Vendor/SocketRocket/LICENSE-examples b/Sources/Vendor/SocketRocket/LICENSE-examples new file mode 100755 index 0000000..1de7813 --- /dev/null +++ b/Sources/Vendor/SocketRocket/LICENSE-examples @@ -0,0 +1,11 @@ +Copyright (c) 2016-present, Facebook, Inc. All rights reserved. + +The examples provided by Facebook are for non-commercial testing and evaluation +purposes only. Facebook reserves all rights not expressly granted. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Sources/Vendor/SocketRocket/Makefile b/Sources/Vendor/SocketRocket/Makefile new file mode 100755 index 0000000..20e5e9b --- /dev/null +++ b/Sources/Vendor/SocketRocket/Makefile @@ -0,0 +1,30 @@ +TEST_SCENARIOS="[1-8]*" +TEST_URL='ws://localhost:9001/' + +all: + $(MAKE) -C SocketRocket + +clean: + $(MAKE) -C SocketRocket clean + +.env: + + ./TestSupport/setup_env.sh .env + +test: .env + + mkdir -p pages/results + bash ./TestSupport/run_test_server.sh $(TEST_SCENARIOS) $(TEST_URL) Debug || open pages/results/index.html && false + open pages/results/index.html + +test_all: .env + + mkdir -p pages/results + bash ./TestSupport/run_test_server.sh '*' $(TEST_URL) Debug || open pages/results/index.html && false + open pages/results/index.html + +test_perf: .env + + mkdir -p pages/results + bash ./TestSupport/run_test_server.sh '9.*' $(TEST_URL) Release || open pages/results/index.html && false + open pages/results/index.html diff --git a/Sources/Vendor/SocketRocket/PATENTS b/Sources/Vendor/SocketRocket/PATENTS new file mode 100755 index 0000000..6c116ef --- /dev/null +++ b/Sources/Vendor/SocketRocket/PATENTS @@ -0,0 +1,33 @@ +Additional Grant of Patent Rights Version 2 + +"Software" means the SocketRocket software distributed by Facebook, Inc. + +Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software +("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable +(subject to the termination provision below) license under any Necessary +Claims, to make, have made, use, sell, offer to sell, import, and otherwise +transfer the Software. For avoidance of doubt, no license is granted under +Facebook’s rights in any patent claims that are infringed by (i) modifications +to the Software made by you or any third party or (ii) the Software in +combination with any software or other technology. + +The license granted hereunder will terminate, automatically and without notice, +if you (or any of your subsidiaries, corporate affiliates or agents) initiate +directly or indirectly, or take a direct financial interest in, any Patent +Assertion: (i) against Facebook or any of its subsidiaries or corporate +affiliates, (ii) against any party if such Patent Assertion arises in whole or +in part from any software, technology, product or service of Facebook or any of +its subsidiaries or corporate affiliates, or (iii) against any party relating +to the Software. Notwithstanding the foregoing, if Facebook or any of its +subsidiaries or corporate affiliates files a lawsuit alleging patent +infringement against you in the first instance, and you respond by filing a +patent infringement counterclaim in that lawsuit against that party that is +unrelated to the Software, the license granted hereunder will not terminate +under section (i) of this paragraph due to such counterclaim. + +A "Necessary Claim" is a claim of a patent owned by Facebook that is +necessarily infringed by the Software standing alone. + +A "Patent Assertion" is any lawsuit or other action alleging direct, indirect, +or contributory infringement or inducement to infringe any patent, including a +cross-claim or counterclaim. diff --git a/Sources/Vendor/SocketRocket/README.md b/Sources/Vendor/SocketRocket/README.md new file mode 100755 index 0000000..0264af6 --- /dev/null +++ b/Sources/Vendor/SocketRocket/README.md @@ -0,0 +1,213 @@ +# SocketRocket + +![Platforms][platforms-svg] +[![License][license-svg]][license-link] + +[![Podspec][podspec-svg]][podspec-link] +[![Carthage Compatible][carthage-svg]](carthage-link) + +[![Build Status][build-status-svg]][build-status-link] + +A conforming WebSocket ([RFC 6455](https://tools.ietf.org/html/rfc6455>)) client library for iOS, macOS and tvOS. + +Test results for SocketRocket [here](http://facebook.github.io/SocketRocket/results/). +You can compare to what modern browsers look like [here](http://autobahn.ws/testsuite/reports/clients/index.html). + +SocketRocket currently conforms to all core ~300 of [Autobahn](http://autobahn.ws/testsuite/>)'s fuzzing tests +(aside from two UTF-8 ones where it is merely *non-strict* tests 6.4.2 and 6.4.4). + +## Features/Design + +- TLS (wss) support, including self-signed certificates. +- Seems to perform quite well. +- Supports HTTP Proxies. +- Supports IPv4/IPv6. +- Supports SSL certificate pinning. +- Sends `ping` and can process `pong` events. +- Asynchronous and non-blocking. Most of the work is done on a background thread. +- Supports iOS, macOS, tvOS. + +## Installing + +There are a few options. Choose one, or just figure it out: + +- **[CocoaPods](https://cocoapods.org)** + + Add the following line to your Podfile: + ```ruby + pod 'SocketRocket' + ``` + Run `pod install`, and you are all set. + +- **[Carthage](https://github.com/carthage/carthage)** + + Add the following line to your Cartfile: + ``` + github "facebook/SocketRocket" + ``` + Run `carthage update`, and you should now have the latest version of `SocketRocket` in your `Carthage` folder. + +- **Using SocketRocket as a sub-project** + + You can also include `SocketRocket` as a subproject inside of your application if you'd prefer, although we do not recommend this, as it will increase your indexing time significantly. To do so, just drag and drop the `SocketRocket.xcodeproj` file into your workspace. + +## API + +### `SRWebSocket` + +The Web Socket. + +#### Note: + +`SRWebSocket` will retain itself between `-(void)open` and when it closes, errors, or fails. +This is similar to how `NSURLConnection` behaves (unlike `NSURLConnection`, `SRWebSocket` won't retain the delegate). + +#### Interface + +```objective-c +@interface SRWebSocket : NSObject + +// Make it with this +- (instancetype)initWithURLRequest:(NSURLRequest *)request; + +// Set this before opening +@property (nonatomic, weak) id delegate; + +// Open with this +- (void)open; + +// Close it with this +- (void)close; + +// Send a Data +- (void)sendData:(nullable NSData *)data error:(NSError **)error; + +// Send a UTF8 String +- (void)sendString:(NSString *)string error:(NSError **)error; + +@end +``` + +### `SRWebSocketDelegate` + +You implement this + +```objective-c +@protocol SRWebSocketDelegate + +@optional + +- (void)webSocketDidOpen:(SRWebSocket *)webSocket; + +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithString:(NSString *)string; +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithData:(NSData *)data; + +- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error; +- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(nullable NSString *)reason wasClean:(BOOL)wasClean; + +@end +``` + +## Testing + +Included are setup scripts for the python testing environment. +It comes packaged with vitualenv so all the dependencies are installed in userland. + +To run the short test from the command line, run: +```bash + make test +``` + +To run all the tests, run: +```bash + make test_all +``` + +The short tests don't include the performance tests +(the test harness is actually the bottleneck, not SocketRocket). + +The first time this is run, it may take a while to install the dependencies. It will be smooth sailing after that. + +You can also run tests inside Xcode, which runs the same thing, but makes it easier to debug. + +- Choose the `SocketRocket` target +- Run the test action (`⌘+U`) + +### TestChat Demo Application + +SocketRocket includes a demo app, TestChat. +It will "chat" with a listening websocket on port 9900. + +#### TestChat Server + +The sever takes a message and broadcasts it to all other connected clients. + +It requires some dependencies though to run. +We also want to reuse the virtualenv we made when we ran the tests. +If you haven't run the tests yet, go into the SocketRocket root directory and type: + +```bash +make test +``` + +This will set up your [virtualenv](https://pypi.python.org/pypi/virtualenv). + +Now, in your terminal: + +```bash +source .env/bin/activate +pip install git+https://github.com/tornadoweb/tornado.git +``` + +In the same terminal session, start the chatroom server: + +```bash +python TestChatServer/py/chatroom.py +``` + +There's also a Go implementation (with the latest weekly) where you can: + +```bash +cd TestChatServer/go +go run chatroom.go +``` + +#### Chatting + +Now, start TestChat.app (just run the target in the Xcode project). +If you had it started already you can hit the refresh button to reconnect. +It should say "Connected!" on top. + +To talk with the app, open up your browser to [http://localhost:9000](http://localhost:9000) and start chatting. + + +## WebSocket Server Implementation Recommendations + +SocketRocket has been used with the following libraries: + +- [Tornado](https://github.com/tornadoweb/tornado) +- Go's [WebSocket package](https://godoc.org/golang.org/x/net/websocket) or Gorilla's [version](http://www.gorillatoolkit.org/pkg/websocket). +- [Autobahn](http://autobahn.ws/testsuite/) (using its fuzzing client). + +The Tornado one is dirt simple and works like a charm. +([IPython notebook](http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html) uses it too). +It's much easier to configure handlers and routes than in Autobahn/twisted. + +## Contributing + +We’re glad you’re interested in SocketRocket, and we’d love to see where you take it. +Please read our [contributing guidelines](https://github.com/facebook/SocketRocket/blob/master/CONTRIBUTING.md) prior to submitting a Pull Request. + + [build-status-svg]: https://img.shields.io/travis/facebook/SocketRocket/master.svg + [build-status-link]: https://travis-ci.org/facebook/SocketRocket/branches + + [license-svg]: https://img.shields.io/badge/license-BSD-lightgrey.svg + [license-link]: https://github.com/facebook/SocketRocket/blob/master/LICENSE + + [podspec-svg]: https://img.shields.io/cocoapods/v/SocketRocket.svg + [podspec-link]: https://cocoapods.org/pods/SocketRocket + + [carthage-svg]: https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat + [carthage-link]: https://github.com/carthage/carthage + + [platforms-svg]: http://img.shields.io/cocoapods/p/SocketRocket.svg?style=flat diff --git a/Sources/Vendor/SocketRocket/SocketRocket.podspec b/Sources/Vendor/SocketRocket/SocketRocket.podspec new file mode 100755 index 0000000..0dbb39d --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket.podspec @@ -0,0 +1,22 @@ +Pod::Spec.new do |s| + s.name = 'SocketRocket' + s.version = '0.5.1' + s.summary = 'A conforming WebSocket (RFC 6455) client library for iOS, macOS and tvOS.' + s.homepage = 'https://github.com/facebook/SocketRocket' + 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.ios.deployment_target = '6.0' + s.osx.deployment_target = '10.8' + s.tvos.deployment_target = '9.0' + + s.ios.frameworks = 'CFNetwork', 'Security' + s.osx.frameworks = 'CoreServices', 'Security' + s.tvos.frameworks = 'CFNetwork', 'Security' + s.libraries = 'icucore' +end diff --git a/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/project.pbxproj b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/project.pbxproj new file mode 100755 index 0000000..30aa8a4 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/project.pbxproj @@ -0,0 +1,1347 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 2D42277F1BB4365C000C1A6C /* SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = F6A12CCF145119B700C1D980 /* SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 2D4227801BB43693000C1A6C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6B208301450F597009315AF /* Foundation.framework */; }; + 2D4227831BB436B1000C1A6C /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6A12CD3145122FC00C1D980 /* Security.framework */; }; + 2D4227851BB43734000C1A6C /* SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = F6A12CD0145119B700C1D980 /* SRWebSocket.m */; }; + 3345DC841C52ACD70083CCB8 /* SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = F6A12CD0145119B700C1D980 /* SRWebSocket.m */; }; + 3345DC871C52ACD70083CCB8 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6A12CD3145122FC00C1D980 /* Security.framework */; }; + 3345DC881C52ACD70083CCB8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6B208301450F597009315AF /* Foundation.framework */; }; + 3345DC8A1C52ACD70083CCB8 /* SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = F6A12CCF145119B700C1D980 /* SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 454A02D61D0FAD010060DFB2 /* SRSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 454A02D41D0FAD010060DFB2 /* SRSecurityPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 454A02D71D0FAD010060DFB2 /* SRSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 454A02D41D0FAD010060DFB2 /* SRSecurityPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 454A02D81D0FAD010060DFB2 /* SRSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 454A02D41D0FAD010060DFB2 /* SRSecurityPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 454FEA7D1D2570F600073768 /* SRPinningSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 454FEA791D2570D400073768 /* SRPinningSecurityPolicy.h */; }; + 454FEA7E1D2570F600073768 /* SRPinningSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 454FEA7A1D2570D400073768 /* SRPinningSecurityPolicy.m */; }; + 454FEA7F1D2570F800073768 /* SRPinningSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 454FEA791D2570D400073768 /* SRPinningSecurityPolicy.h */; }; + 454FEA801D2570F800073768 /* SRPinningSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 454FEA7A1D2570D400073768 /* SRPinningSecurityPolicy.m */; }; + 454FEA811D2570F900073768 /* SRPinningSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 454FEA791D2570D400073768 /* SRPinningSecurityPolicy.h */; }; + 454FEA821D2570F900073768 /* SRPinningSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 454FEA7A1D2570D400073768 /* SRPinningSecurityPolicy.m */; }; + 454FEA851D25719900073768 /* SRSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 454FEA831D25717C00073768 /* SRSecurityPolicy.m */; }; + 454FEA861D25719A00073768 /* SRSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 454FEA831D25717C00073768 /* SRSecurityPolicy.m */; }; + 454FEA871D25719A00073768 /* SRSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 454FEA831D25717C00073768 /* SRSecurityPolicy.m */; }; + 8105E4801CDD67B400AA12DB /* SRAutobahnTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8105E47A1CDD679A00AA12DB /* SRAutobahnTests.m */; }; + 8105E4821CDD67BD00AA12DB /* SRTWebSocketOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 8105E4771CDD679A00AA12DB /* SRTWebSocketOperation.m */; }; + 8105E4AE1CDD6E6200AA12DB /* SRAutobahnOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 8105E4AD1CDD6E6200AA12DB /* SRAutobahnOperation.m */; }; + 8105E5281CDD98E100AA12DB /* autobahn_configuration.json in Resources */ = {isa = PBXBuildFile; fileRef = 8105E5271CDD98E100AA12DB /* autobahn_configuration.json */; }; + 8117C4231D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8117C4221D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h */; }; + 8117C4241D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8117C4221D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h */; }; + 8117C4251D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8117C4221D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h */; }; + 8117C4261D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8117C4221D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h */; }; + 8117C4301D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8117C42F1D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h */; }; + 8117C4311D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8117C42F1D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h */; }; + 8117C4321D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8117C42F1D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h */; }; + 8117C4331D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 8117C42F1D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h */; }; + 811934BC1CDAF725003AB243 /* SocketRocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 555E0EB11C51E56D00E6BB92 /* SocketRocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 811934BE1CDAF725003AB243 /* SocketRocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 555E0EB11C51E56D00E6BB92 /* SocketRocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 811934C01CDAF726003AB243 /* SocketRocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 555E0EB11C51E56D00E6BB92 /* SocketRocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 813364001D091E170062E28D /* SRProxyConnect.h in Headers */ = {isa = PBXBuildFile; fileRef = 4861E7731D022211002FAB1D /* SRProxyConnect.h */; }; + 813364041D091E170062E28D /* SRProxyConnect.h in Headers */ = {isa = PBXBuildFile; fileRef = 4861E7731D022211002FAB1D /* SRProxyConnect.h */; }; + 813364081D091E180062E28D /* SRProxyConnect.h in Headers */ = {isa = PBXBuildFile; fileRef = 4861E7731D022211002FAB1D /* SRProxyConnect.h */; }; + 8133640C1D091E1B0062E28D /* SRProxyConnect.m in Sources */ = {isa = PBXBuildFile; fileRef = 4861E7741D022211002FAB1D /* SRProxyConnect.m */; }; + 8133640E1D091E1B0062E28D /* SRProxyConnect.m in Sources */ = {isa = PBXBuildFile; fileRef = 4861E7741D022211002FAB1D /* SRProxyConnect.m */; }; + 8133640F1D091E1C0062E28D /* SRProxyConnect.m in Sources */ = {isa = PBXBuildFile; fileRef = 4861E7741D022211002FAB1D /* SRProxyConnect.m */; }; + 815FE7261D497D720085FDA5 /* SRConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 815FE7241D497D720085FDA5 /* SRConstants.h */; }; + 815FE7271D497D720085FDA5 /* SRConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 815FE7241D497D720085FDA5 /* SRConstants.h */; }; + 815FE7281D497D720085FDA5 /* SRConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 815FE7241D497D720085FDA5 /* SRConstants.h */; }; + 815FE7291D497D720085FDA5 /* SRConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 815FE7241D497D720085FDA5 /* SRConstants.h */; }; + 815FE72A1D497D720085FDA5 /* SRConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 815FE7251D497D720085FDA5 /* SRConstants.m */; }; + 815FE72B1D497D720085FDA5 /* SRConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 815FE7251D497D720085FDA5 /* SRConstants.m */; }; + 815FE72C1D497D720085FDA5 /* SRConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 815FE7251D497D720085FDA5 /* SRConstants.m */; }; + 815FE72D1D497D720085FDA5 /* SRConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 815FE7251D497D720085FDA5 /* SRConstants.m */; }; + 817491A91D1C8C33006E09DF /* SRMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 817491A61D1C8C33006E09DF /* SRMutex.h */; }; + 817491AA1D1C8C33006E09DF /* SRMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 817491A61D1C8C33006E09DF /* SRMutex.h */; }; + 817491AB1D1C8C33006E09DF /* SRMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 817491A61D1C8C33006E09DF /* SRMutex.h */; }; + 817491AD1D1C8C33006E09DF /* SRMutex.m in Sources */ = {isa = PBXBuildFile; fileRef = 817491A71D1C8C33006E09DF /* SRMutex.m */; }; + 817491AE1D1C8C33006E09DF /* SRMutex.m in Sources */ = {isa = PBXBuildFile; fileRef = 817491A71D1C8C33006E09DF /* SRMutex.m */; }; + 817491AF1D1C8C33006E09DF /* SRMutex.m in Sources */ = {isa = PBXBuildFile; fileRef = 817491A71D1C8C33006E09DF /* SRMutex.m */; }; + 817995871CE139700084DA37 /* SRDelegateController.h in Headers */ = {isa = PBXBuildFile; fileRef = 817995841CE139700084DA37 /* SRDelegateController.h */; }; + 817995881CE139700084DA37 /* SRDelegateController.h in Headers */ = {isa = PBXBuildFile; fileRef = 817995841CE139700084DA37 /* SRDelegateController.h */; }; + 817995891CE139700084DA37 /* SRDelegateController.h in Headers */ = {isa = PBXBuildFile; fileRef = 817995841CE139700084DA37 /* SRDelegateController.h */; }; + 8179958B1CE139700084DA37 /* SRDelegateController.m in Sources */ = {isa = PBXBuildFile; fileRef = 817995851CE139700084DA37 /* SRDelegateController.m */; }; + 8179958C1CE139700084DA37 /* SRDelegateController.m in Sources */ = {isa = PBXBuildFile; fileRef = 817995851CE139700084DA37 /* SRDelegateController.m */; }; + 8179958D1CE139700084DA37 /* SRDelegateController.m in Sources */ = {isa = PBXBuildFile; fileRef = 817995851CE139700084DA37 /* SRDelegateController.m */; }; + 817996801CE184F40084DA37 /* SRAutobahnUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 8179967F1CE184F40084DA37 /* SRAutobahnUtilities.m */; }; + 81900A4D1D18C9CC0015A290 /* SRLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 81900A4A1D18C9CC0015A290 /* SRLog.h */; }; + 81900A4E1D18C9CC0015A290 /* SRLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 81900A4A1D18C9CC0015A290 /* SRLog.h */; }; + 81900A4F1D18C9CC0015A290 /* SRLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 81900A4A1D18C9CC0015A290 /* SRLog.h */; }; + 81900A511D18C9CC0015A290 /* SRLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 81900A4B1D18C9CC0015A290 /* SRLog.m */; }; + 81900A521D18C9CC0015A290 /* SRLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 81900A4B1D18C9CC0015A290 /* SRLog.m */; }; + 81900A531D18C9CC0015A290 /* SRLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 81900A4B1D18C9CC0015A290 /* SRLog.m */; }; + 81AFCD661D4C431C00B3AFC9 /* libicucore.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 81AFCD651D4C431C00B3AFC9 /* libicucore.tbd */; }; + 81B22EC61CE42D7E0073C636 /* SRError.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B22EC31CE42D7E0073C636 /* SRError.h */; }; + 81B22EC71CE42D7E0073C636 /* SRError.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B22EC31CE42D7E0073C636 /* SRError.h */; }; + 81B22EC81CE42D7E0073C636 /* SRError.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B22EC31CE42D7E0073C636 /* SRError.h */; }; + 81B22ECA1CE42D7E0073C636 /* SRError.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B22EC41CE42D7E0073C636 /* SRError.m */; }; + 81B22ECB1CE42D7E0073C636 /* SRError.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B22EC41CE42D7E0073C636 /* SRError.m */; }; + 81B22ECC1CE42D7E0073C636 /* SRError.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B22EC41CE42D7E0073C636 /* SRError.m */; }; + 81B22EE51CE43ECC0073C636 /* SRURLUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B22EE21CE43ECC0073C636 /* SRURLUtilities.h */; }; + 81B22EE61CE43ECC0073C636 /* SRURLUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B22EE21CE43ECC0073C636 /* SRURLUtilities.h */; }; + 81B22EE71CE43ECC0073C636 /* SRURLUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B22EE21CE43ECC0073C636 /* SRURLUtilities.h */; }; + 81B22EE91CE43ECC0073C636 /* SRURLUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B22EE31CE43ECC0073C636 /* SRURLUtilities.m */; }; + 81B22EEA1CE43ECC0073C636 /* SRURLUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B22EE31CE43ECC0073C636 /* SRURLUtilities.m */; }; + 81B22EEB1CE43ECC0073C636 /* SRURLUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B22EE31CE43ECC0073C636 /* SRURLUtilities.m */; }; + 81B31C151CDC404100D86D43 /* SRIOConsumer.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C0F1CDC404100D86D43 /* SRIOConsumer.h */; }; + 81B31C161CDC404100D86D43 /* SRIOConsumer.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C0F1CDC404100D86D43 /* SRIOConsumer.h */; }; + 81B31C171CDC404100D86D43 /* SRIOConsumer.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C0F1CDC404100D86D43 /* SRIOConsumer.h */; }; + 81B31C191CDC404100D86D43 /* SRIOConsumer.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C101CDC404100D86D43 /* SRIOConsumer.m */; }; + 81B31C1A1CDC404100D86D43 /* SRIOConsumer.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C101CDC404100D86D43 /* SRIOConsumer.m */; }; + 81B31C1B1CDC404100D86D43 /* SRIOConsumer.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C101CDC404100D86D43 /* SRIOConsumer.m */; }; + 81B31C1D1CDC404100D86D43 /* SRIOConsumerPool.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C111CDC404100D86D43 /* SRIOConsumerPool.h */; }; + 81B31C1E1CDC404100D86D43 /* SRIOConsumerPool.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C111CDC404100D86D43 /* SRIOConsumerPool.h */; }; + 81B31C1F1CDC404100D86D43 /* SRIOConsumerPool.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C111CDC404100D86D43 /* SRIOConsumerPool.h */; }; + 81B31C211CDC404100D86D43 /* SRIOConsumerPool.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C121CDC404100D86D43 /* SRIOConsumerPool.m */; }; + 81B31C221CDC404100D86D43 /* SRIOConsumerPool.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C121CDC404100D86D43 /* SRIOConsumerPool.m */; }; + 81B31C231CDC404100D86D43 /* SRIOConsumerPool.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C121CDC404100D86D43 /* SRIOConsumerPool.m */; }; + 81B31C2E1CDC406B00D86D43 /* SRHash.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C2B1CDC406B00D86D43 /* SRHash.h */; }; + 81B31C2F1CDC406B00D86D43 /* SRHash.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C2B1CDC406B00D86D43 /* SRHash.h */; }; + 81B31C301CDC406B00D86D43 /* SRHash.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C2B1CDC406B00D86D43 /* SRHash.h */; }; + 81B31C321CDC406B00D86D43 /* SRHash.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C2C1CDC406B00D86D43 /* SRHash.m */; }; + 81B31C331CDC406B00D86D43 /* SRHash.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C2C1CDC406B00D86D43 /* SRHash.m */; }; + 81B31C341CDC406B00D86D43 /* SRHash.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C2C1CDC406B00D86D43 /* SRHash.m */; }; + 81B31C601CDC444900D86D43 /* SRRunLoopThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C5D1CDC444900D86D43 /* SRRunLoopThread.h */; }; + 81B31C611CDC444900D86D43 /* SRRunLoopThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C5D1CDC444900D86D43 /* SRRunLoopThread.h */; }; + 81B31C621CDC444900D86D43 /* SRRunLoopThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C5D1CDC444900D86D43 /* SRRunLoopThread.h */; }; + 81B31C641CDC444900D86D43 /* SRRunLoopThread.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C5E1CDC444900D86D43 /* SRRunLoopThread.m */; }; + 81B31C651CDC444900D86D43 /* SRRunLoopThread.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C5E1CDC444900D86D43 /* SRRunLoopThread.m */; }; + 81B31C661CDC444900D86D43 /* SRRunLoopThread.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C5E1CDC444900D86D43 /* SRRunLoopThread.m */; }; + 81C22BC31D124168007BFDDF /* SRHTTPConnectMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = 81C22BC01D124168007BFDDF /* SRHTTPConnectMessage.h */; }; + 81C22BC41D124168007BFDDF /* SRHTTPConnectMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = 81C22BC01D124168007BFDDF /* SRHTTPConnectMessage.h */; }; + 81C22BC51D124168007BFDDF /* SRHTTPConnectMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = 81C22BC01D124168007BFDDF /* SRHTTPConnectMessage.h */; }; + 81C22BC71D124168007BFDDF /* SRHTTPConnectMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 81C22BC11D124168007BFDDF /* SRHTTPConnectMessage.m */; }; + 81C22BC81D124168007BFDDF /* SRHTTPConnectMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 81C22BC11D124168007BFDDF /* SRHTTPConnectMessage.m */; }; + 81C22BC91D124168007BFDDF /* SRHTTPConnectMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 81C22BC11D124168007BFDDF /* SRHTTPConnectMessage.m */; }; + 81C22BF91D1256E1007BFDDF /* SRRandom.h in Headers */ = {isa = PBXBuildFile; fileRef = 81C22BF61D1256E1007BFDDF /* SRRandom.h */; }; + 81C22BFA1D1256E1007BFDDF /* SRRandom.h in Headers */ = {isa = PBXBuildFile; fileRef = 81C22BF61D1256E1007BFDDF /* SRRandom.h */; }; + 81C22BFB1D1256E1007BFDDF /* SRRandom.h in Headers */ = {isa = PBXBuildFile; fileRef = 81C22BF61D1256E1007BFDDF /* SRRandom.h */; }; + 81C22BFD1D1256E1007BFDDF /* SRRandom.m in Sources */ = {isa = PBXBuildFile; fileRef = 81C22BF71D1256E1007BFDDF /* SRRandom.m */; }; + 81C22BFE1D1256E1007BFDDF /* SRRandom.m in Sources */ = {isa = PBXBuildFile; fileRef = 81C22BF71D1256E1007BFDDF /* SRRandom.m */; }; + 81C22BFF1D1256E1007BFDDF /* SRRandom.m in Sources */ = {isa = PBXBuildFile; fileRef = 81C22BF71D1256E1007BFDDF /* SRRandom.m */; }; + 81C68CD41D2CBE0A00A1D005 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81C68CD31D2CBE0A00A1D005 /* CFNetwork.framework */; }; + 81C68CDF1D2CBE1900A1D005 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81C68CDE1D2CBE1900A1D005 /* CFNetwork.framework */; }; + 81C68CEE1D2CBE9400A1D005 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6A12CD51451231B00C1D980 /* CFNetwork.framework */; }; + 81C68CF11D2CBE9F00A1D005 /* libicucore.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 81C68CF01D2CBE9F00A1D005 /* libicucore.tbd */; }; + 81C68CF61D2CBED100A1D005 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6A12CD3145122FC00C1D980 /* Security.framework */; }; + 81C68D071D2CBF6A00A1D005 /* libicucore.A.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 81C68D061D2CBF6A00A1D005 /* libicucore.A.tbd */; }; + 81C68D0E1D2CBFA800A1D005 /* libicucore.A.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 81C68D0D1D2CBFA800A1D005 /* libicucore.A.tbd */; }; + 81CD05D81CEEC47300497F47 /* NSURLRequest+SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 81CD05D51CEEC47300497F47 /* NSURLRequest+SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 81CD05D91CEEC47300497F47 /* NSURLRequest+SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 81CD05D51CEEC47300497F47 /* NSURLRequest+SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 81CD05DA1CEEC47300497F47 /* NSURLRequest+SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 81CD05D51CEEC47300497F47 /* NSURLRequest+SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 81CD05DC1CEEC47300497F47 /* NSURLRequest+SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 81CD05D61CEEC47300497F47 /* NSURLRequest+SRWebSocket.m */; }; + 81CD05DD1CEEC47300497F47 /* NSURLRequest+SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 81CD05D61CEEC47300497F47 /* NSURLRequest+SRWebSocket.m */; }; + 81CD05DE1CEEC47300497F47 /* NSURLRequest+SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 81CD05D61CEEC47300497F47 /* NSURLRequest+SRWebSocket.m */; }; + 81CD05FE1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 81CD05FB1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 81CD05FF1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 81CD05FB1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 81CD06001CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 81CD05FB1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 81CD06021CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 81CD05FC1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m */; }; + 81CD06031CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 81CD05FC1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m */; }; + 81CD06041CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 81CD05FC1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m */; }; + 81D647611D2CA78800690609 /* NSURLRequest+SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 81CD05D61CEEC47300497F47 /* NSURLRequest+SRWebSocket.m */; }; + 81D647621D2CA78800690609 /* SRError.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B22EC41CE42D7E0073C636 /* SRError.m */; }; + 81D647631D2CA78800690609 /* SRIOConsumer.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C101CDC404100D86D43 /* SRIOConsumer.m */; }; + 81D647641D2CA78800690609 /* SRHTTPConnectMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 81C22BC11D124168007BFDDF /* SRHTTPConnectMessage.m */; }; + 81D647651D2CA78800690609 /* SRPinningSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 454FEA7A1D2570D400073768 /* SRPinningSecurityPolicy.m */; }; + 81D647661D2CA78800690609 /* SRSecurityPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 454FEA831D25717C00073768 /* SRSecurityPolicy.m */; }; + 81D647671D2CA78800690609 /* NSRunLoop+SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 81CD05FC1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m */; }; + 81D647681D2CA78800690609 /* SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = F6A12CD0145119B700C1D980 /* SRWebSocket.m */; }; + 81D647691D2CA78800690609 /* SRRandom.m in Sources */ = {isa = PBXBuildFile; fileRef = 81C22BF71D1256E1007BFDDF /* SRRandom.m */; }; + 81D6476A1D2CA78800690609 /* SRIOConsumerPool.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C121CDC404100D86D43 /* SRIOConsumerPool.m */; }; + 81D6476B1D2CA78800690609 /* SRURLUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B22EE31CE43ECC0073C636 /* SRURLUtilities.m */; }; + 81D6476C1D2CA78800690609 /* SRProxyConnect.m in Sources */ = {isa = PBXBuildFile; fileRef = 4861E7741D022211002FAB1D /* SRProxyConnect.m */; }; + 81D6476D1D2CA78800690609 /* SRMutex.m in Sources */ = {isa = PBXBuildFile; fileRef = 817491A71D1C8C33006E09DF /* SRMutex.m */; }; + 81D6476E1D2CA78800690609 /* SRRunLoopThread.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C5E1CDC444900D86D43 /* SRRunLoopThread.m */; }; + 81D6476F1D2CA78800690609 /* SRLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 81900A4B1D18C9CC0015A290 /* SRLog.m */; }; + 81D647701D2CA78800690609 /* SRHash.m in Sources */ = {isa = PBXBuildFile; fileRef = 81B31C2C1CDC406B00D86D43 /* SRHash.m */; }; + 81D647711D2CA78800690609 /* SRDelegateController.m in Sources */ = {isa = PBXBuildFile; fileRef = 817995851CE139700084DA37 /* SRDelegateController.m */; }; + 81D647741D2CA78800690609 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6A12CD3145122FC00C1D980 /* Security.framework */; }; + 81D647751D2CA78800690609 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6B208301450F597009315AF /* Foundation.framework */; }; + 81D647771D2CA78800690609 /* SRURLUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B22EE21CE43ECC0073C636 /* SRURLUtilities.h */; }; + 81D647781D2CA78800690609 /* SRPinningSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 454FEA791D2570D400073768 /* SRPinningSecurityPolicy.h */; }; + 81D647791D2CA78800690609 /* SRIOConsumer.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C0F1CDC404100D86D43 /* SRIOConsumer.h */; }; + 81D6477A1D2CA78800690609 /* NSRunLoop+SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 81CD05FB1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 81D6477B1D2CA78800690609 /* SRSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 454A02D41D0FAD010060DFB2 /* SRSecurityPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 81D6477C1D2CA78800690609 /* NSURLRequest+SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 81CD05D51CEEC47300497F47 /* NSURLRequest+SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 81D6477D1D2CA78800690609 /* SRLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 81900A4A1D18C9CC0015A290 /* SRLog.h */; }; + 81D6477E1D2CA78800690609 /* SRIOConsumerPool.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C111CDC404100D86D43 /* SRIOConsumerPool.h */; }; + 81D6477F1D2CA78800690609 /* SRProxyConnect.h in Headers */ = {isa = PBXBuildFile; fileRef = 4861E7731D022211002FAB1D /* SRProxyConnect.h */; }; + 81D647801D2CA78800690609 /* SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = F6A12CCF145119B700C1D980 /* SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 81D647811D2CA78800690609 /* SRHash.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C2B1CDC406B00D86D43 /* SRHash.h */; }; + 81D647821D2CA78800690609 /* SocketRocket.h in Headers */ = {isa = PBXBuildFile; fileRef = 555E0EB11C51E56D00E6BB92 /* SocketRocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 81D647831D2CA78800690609 /* SRRandom.h in Headers */ = {isa = PBXBuildFile; fileRef = 81C22BF61D1256E1007BFDDF /* SRRandom.h */; }; + 81D647841D2CA78800690609 /* SRHTTPConnectMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = 81C22BC01D124168007BFDDF /* SRHTTPConnectMessage.h */; }; + 81D647851D2CA78800690609 /* SRDelegateController.h in Headers */ = {isa = PBXBuildFile; fileRef = 817995841CE139700084DA37 /* SRDelegateController.h */; }; + 81D647861D2CA78800690609 /* SRMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 817491A61D1C8C33006E09DF /* SRMutex.h */; }; + 81D647871D2CA78800690609 /* SRError.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B22EC31CE42D7E0073C636 /* SRError.h */; }; + 81D647881D2CA78800690609 /* SRRunLoopThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 81B31C5D1CDC444900D86D43 /* SRRunLoopThread.h */; }; + 81D647B51D2CA8E200690609 /* SocketRocket.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81D6478D1D2CA78800690609 /* SocketRocket.framework */; }; + 81DCD1241D2D9235002501A2 /* libicucore.A.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 81C68D0D1D2CBFA800A1D005 /* libicucore.A.tbd */; }; + 81E8A6A21D4C41E000916C7E /* SocketRocket.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81D6478D1D2CA78800690609 /* SocketRocket.framework */; }; + 81E8A6A31D4C41E000916C7E /* SocketRocket.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 81D6478D1D2CA78800690609 /* SocketRocket.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + F5391CBE1D2F4B4700606A81 /* SRSIMDHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = F5391CBC1D2F4B4700606A81 /* SRSIMDHelpers.h */; }; + F5391CBF1D2F4B4700606A81 /* SRSIMDHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = F5391CBC1D2F4B4700606A81 /* SRSIMDHelpers.h */; }; + F5391CC01D2F4B4700606A81 /* SRSIMDHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = F5391CBC1D2F4B4700606A81 /* SRSIMDHelpers.h */; }; + F5391CC11D2F4B4700606A81 /* SRSIMDHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = F5391CBC1D2F4B4700606A81 /* SRSIMDHelpers.h */; }; + F5391CC21D2F4B4700606A81 /* SRSIMDHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = F5391CBD1D2F4B4700606A81 /* SRSIMDHelpers.m */; }; + F5391CC31D2F4B4700606A81 /* SRSIMDHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = F5391CBD1D2F4B4700606A81 /* SRSIMDHelpers.m */; }; + F5391CC41D2F4B4700606A81 /* SRSIMDHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = F5391CBD1D2F4B4700606A81 /* SRSIMDHelpers.m */; }; + F5391CC51D2F4B4700606A81 /* SRSIMDHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = F5391CBD1D2F4B4700606A81 /* SRSIMDHelpers.m */; }; + F6016C8814620EC70037BB3D /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6A12CD3145122FC00C1D980 /* Security.framework */; }; + F61A0DC81625F44D00365EBD /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F61A0DC71625F44D00365EBD /* Default-568h@2x.png */; }; + F62417E614D52F3C003CE997 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F62417E514D52F3C003CE997 /* UIKit.framework */; }; + F62417E714D52F3C003CE997 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6B208301450F597009315AF /* Foundation.framework */; }; + F62417EF14D52F3C003CE997 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F62417ED14D52F3C003CE997 /* InfoPlist.strings */; }; + F62417F114D52F3C003CE997 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F62417F014D52F3C003CE997 /* main.m */; }; + F62417F514D52F3C003CE997 /* TCAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F62417F414D52F3C003CE997 /* TCAppDelegate.m */; }; + F62417F814D52F3C003CE997 /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F62417F614D52F3C003CE997 /* MainStoryboard.storyboard */; }; + F62417FB14D52F3C003CE997 /* TCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F62417FA14D52F3C003CE997 /* TCViewController.m */; }; + F624180114D5300C003CE997 /* TCChatCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F624180014D5300C003CE997 /* TCChatCell.m */; }; + F624180314D53449003CE997 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6A12CD51451231B00C1D980 /* CFNetwork.framework */; }; + F624180414D53449003CE997 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6A12CD3145122FC00C1D980 /* Security.framework */; }; + F6396B86153E67EC00345B5E /* SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = F6A12CD0145119B700C1D980 /* SRWebSocket.m */; }; + F668C8AA153E92F90044DBAC /* SRWebSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = F6A12CCF145119B700C1D980 /* SRWebSocket.h */; settings = {ATTRIBUTES = (Public, ); }; }; + F6AE45241459071C0022AF3C /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6A12CD51451231B00C1D980 /* CFNetwork.framework */; }; + F6BDA806145900D200FE3253 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6B208301450F597009315AF /* Foundation.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 81D647B31D2CA8DD00690609 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = F6B208241450F597009315AF /* Project object */; + proxyType = 1; + remoteGlobalIDString = 81D6475F1D2CA78800690609; + remoteInfo = "SocketRocket-iOS"; + }; + 81E8A6A01D4C41DA00916C7E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = F6B208241450F597009315AF /* Project object */; + proxyType = 1; + remoteGlobalIDString = 2D4227611BB4358C000C1A6C; + remoteInfo = "SocketRocket-iOS-Dynamic"; + }; + 81E8A6A41D4C41E000916C7E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = F6B208241450F597009315AF /* Project object */; + proxyType = 1; + remoteGlobalIDString = 81D6475F1D2CA78800690609; + remoteInfo = "SocketRocket-iOS"; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 81E8A6A61D4C41E000916C7E /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 81E8A6A31D4C41E000916C7E /* SocketRocket.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 2D4227621BB4358C000C1A6C /* SocketRocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SocketRocket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 3345DC901C52ACD70083CCB8 /* SocketRocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SocketRocket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 454A02D41D0FAD010060DFB2 /* SRSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SRSecurityPolicy.h; path = SocketRocket/SRSecurityPolicy.h; sourceTree = SOURCE_ROOT; }; + 454FEA791D2570D400073768 /* SRPinningSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRPinningSecurityPolicy.h; sourceTree = ""; }; + 454FEA7A1D2570D400073768 /* SRPinningSecurityPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRPinningSecurityPolicy.m; sourceTree = ""; }; + 454FEA831D25717C00073768 /* SRSecurityPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRSecurityPolicy.m; sourceTree = ""; }; + 4861E7731D022211002FAB1D /* SRProxyConnect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRProxyConnect.h; sourceTree = ""; }; + 4861E7741D022211002FAB1D /* SRProxyConnect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRProxyConnect.m; sourceTree = ""; }; + 555E0EB11C51E56D00E6BB92 /* SocketRocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocketRocket.h; sourceTree = ""; }; + 8105E4761CDD679A00AA12DB /* SRTWebSocketOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SRTWebSocketOperation.h; sourceTree = ""; }; + 8105E4771CDD679A00AA12DB /* SRTWebSocketOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SRTWebSocketOperation.m; sourceTree = ""; }; + 8105E4791CDD679A00AA12DB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 8105E47A1CDD679A00AA12DB /* SRAutobahnTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SRAutobahnTests.m; sourceTree = ""; }; + 8105E4AC1CDD6E6200AA12DB /* SRAutobahnOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRAutobahnOperation.h; sourceTree = ""; }; + 8105E4AD1CDD6E6200AA12DB /* SRAutobahnOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRAutobahnOperation.m; sourceTree = ""; }; + 8105E5271CDD98E100AA12DB /* autobahn_configuration.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = autobahn_configuration.json; sourceTree = ""; }; + 8117C4221D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSURLRequest+SRWebSocketPrivate.h"; path = "Internal/NSURLRequest+SRWebSocketPrivate.h"; sourceTree = ""; }; + 8117C42F1D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSRunLoop+SRWebSocketPrivate.h"; path = "Internal/NSRunLoop+SRWebSocketPrivate.h"; sourceTree = ""; }; + 811934B11CDAF711003AB243 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 815FE7241D497D720085FDA5 /* SRConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SRConstants.h; path = SocketRocket/Internal/SRConstants.h; sourceTree = SOURCE_ROOT; }; + 815FE7251D497D720085FDA5 /* SRConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SRConstants.m; path = SocketRocket/Internal/SRConstants.m; sourceTree = SOURCE_ROOT; }; + 817491A61D1C8C33006E09DF /* SRMutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRMutex.h; sourceTree = ""; }; + 817491A71D1C8C33006E09DF /* SRMutex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRMutex.m; sourceTree = ""; }; + 817995841CE139700084DA37 /* SRDelegateController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRDelegateController.h; sourceTree = ""; }; + 817995851CE139700084DA37 /* SRDelegateController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRDelegateController.m; sourceTree = ""; }; + 8179967E1CE184F40084DA37 /* SRAutobahnUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRAutobahnUtilities.h; sourceTree = ""; }; + 8179967F1CE184F40084DA37 /* SRAutobahnUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRAutobahnUtilities.m; sourceTree = ""; }; + 81900A4A1D18C9CC0015A290 /* SRLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRLog.h; sourceTree = ""; }; + 81900A4B1D18C9CC0015A290 /* SRLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRLog.m; sourceTree = ""; }; + 81AFCD651D4C431C00B3AFC9 /* libicucore.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libicucore.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/usr/lib/libicucore.tbd; sourceTree = DEVELOPER_DIR; }; + 81B22EC31CE42D7E0073C636 /* SRError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRError.h; sourceTree = ""; }; + 81B22EC41CE42D7E0073C636 /* SRError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRError.m; sourceTree = ""; }; + 81B22EE21CE43ECC0073C636 /* SRURLUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRURLUtilities.h; sourceTree = ""; }; + 81B22EE31CE43ECC0073C636 /* SRURLUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRURLUtilities.m; sourceTree = ""; }; + 81B31C0F1CDC404100D86D43 /* SRIOConsumer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRIOConsumer.h; sourceTree = ""; }; + 81B31C101CDC404100D86D43 /* SRIOConsumer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRIOConsumer.m; sourceTree = ""; }; + 81B31C111CDC404100D86D43 /* SRIOConsumerPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRIOConsumerPool.h; sourceTree = ""; }; + 81B31C121CDC404100D86D43 /* SRIOConsumerPool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRIOConsumerPool.m; sourceTree = ""; }; + 81B31C2B1CDC406B00D86D43 /* SRHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRHash.h; sourceTree = ""; }; + 81B31C2C1CDC406B00D86D43 /* SRHash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRHash.m; sourceTree = ""; }; + 81B31C5D1CDC444900D86D43 /* SRRunLoopThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRRunLoopThread.h; sourceTree = ""; }; + 81B31C5E1CDC444900D86D43 /* SRRunLoopThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRRunLoopThread.m; sourceTree = ""; }; + 81C22BC01D124168007BFDDF /* SRHTTPConnectMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRHTTPConnectMessage.h; sourceTree = ""; }; + 81C22BC11D124168007BFDDF /* SRHTTPConnectMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRHTTPConnectMessage.m; sourceTree = ""; }; + 81C22BF61D1256E1007BFDDF /* SRRandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRRandom.h; sourceTree = ""; }; + 81C22BF71D1256E1007BFDDF /* SRRandom.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRRandom.m; sourceTree = ""; }; + 81C68CD31D2CBE0A00A1D005 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CFNetwork.framework; sourceTree = DEVELOPER_DIR; }; + 81C68CDE1D2CBE1900A1D005 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CFNetwork.framework; sourceTree = DEVELOPER_DIR; }; + 81C68CF01D2CBE9F00A1D005 /* libicucore.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libicucore.tbd; path = usr/lib/libicucore.tbd; sourceTree = SDKROOT; }; + 81C68D061D2CBF6A00A1D005 /* libicucore.A.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libicucore.A.tbd; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/lib/libicucore.A.tbd; sourceTree = DEVELOPER_DIR; }; + 81C68D0D1D2CBFA800A1D005 /* libicucore.A.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libicucore.A.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libicucore.A.tbd; sourceTree = DEVELOPER_DIR; }; + 81CD05D51CEEC47300497F47 /* NSURLRequest+SRWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURLRequest+SRWebSocket.h"; sourceTree = ""; }; + 81CD05D61CEEC47300497F47 /* NSURLRequest+SRWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURLRequest+SRWebSocket.m"; sourceTree = ""; }; + 81CD05FB1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSRunLoop+SRWebSocket.h"; sourceTree = ""; }; + 81CD05FC1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSRunLoop+SRWebSocket.m"; sourceTree = ""; }; + 81D6474A1D2CA6A100690609 /* Common.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Common.xcconfig; sourceTree = ""; }; + 81D6474C1D2CA6A100690609 /* iOS.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = iOS.xcconfig; sourceTree = ""; }; + 81D6474D1D2CA6A100690609 /* macOS.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = macOS.xcconfig; sourceTree = ""; }; + 81D6474E1D2CA6A100690609 /* tvOS.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = tvOS.xcconfig; sourceTree = ""; }; + 81D6474F1D2CA6A100690609 /* watchOS.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = watchOS.xcconfig; sourceTree = ""; }; + 81D647511D2CA6A100690609 /* Application.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Application.xcconfig; sourceTree = ""; }; + 81D647521D2CA6A100690609 /* DynamicFramework.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = DynamicFramework.xcconfig; sourceTree = ""; }; + 81D647531D2CA6A100690609 /* LogicTests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = LogicTests.xcconfig; sourceTree = ""; }; + 81D647541D2CA6A100690609 /* StaticFramework.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = StaticFramework.xcconfig; sourceTree = ""; }; + 81D647561D2CA6A100690609 /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; + 81D647571D2CA6A100690609 /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; + 81D647581D2CA6A100690609 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; + 81D647591D2CA6A100690609 /* SocketRocket-iOS-Dynamic.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "SocketRocket-iOS-Dynamic.xcconfig"; sourceTree = ""; }; + 81D6475A1D2CA6A100690609 /* SocketRocket-iOS.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "SocketRocket-iOS.xcconfig"; sourceTree = ""; }; + 81D6475B1D2CA6A100690609 /* SocketRocket-macOS.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "SocketRocket-macOS.xcconfig"; sourceTree = ""; }; + 81D6475C1D2CA6A100690609 /* SocketRocket-tvOS.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "SocketRocket-tvOS.xcconfig"; sourceTree = ""; }; + 81D6475D1D2CA6A100690609 /* SocketRocketTests-iOS.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "SocketRocketTests-iOS.xcconfig"; sourceTree = ""; }; + 81D6478D1D2CA78800690609 /* SocketRocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SocketRocket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 81E8A69A1D4C417A00916C7E /* TestChat-iOS.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "TestChat-iOS.xcconfig"; sourceTree = ""; }; + F5391CBC1D2F4B4700606A81 /* SRSIMDHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRSIMDHelpers.h; sourceTree = ""; }; + F5391CBD1D2F4B4700606A81 /* SRSIMDHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRSIMDHelpers.m; sourceTree = ""; }; + F61A0DC71625F44D00365EBD /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-568h@2x.png"; path = "en.lproj/Default-568h@2x.png"; sourceTree = ""; }; + F62417E314D52F3C003CE997 /* TestChat.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TestChat.app; sourceTree = BUILT_PRODUCTS_DIR; }; + F62417E514D52F3C003CE997 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; + F62417EC14D52F3C003CE997 /* TestChat-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "TestChat-Info.plist"; sourceTree = ""; }; + F62417EE14D52F3C003CE997 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + F62417F014D52F3C003CE997 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + F62417F314D52F3C003CE997 /* TCAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TCAppDelegate.h; sourceTree = ""; }; + F62417F414D52F3C003CE997 /* TCAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TCAppDelegate.m; sourceTree = ""; }; + F62417F714D52F3C003CE997 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard.storyboard; sourceTree = ""; }; + F62417F914D52F3C003CE997 /* TCViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TCViewController.h; sourceTree = ""; }; + F62417FA14D52F3C003CE997 /* TCViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TCViewController.m; sourceTree = ""; }; + F62417FF14D5300C003CE997 /* TCChatCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TCChatCell.h; sourceTree = ""; }; + F624180014D5300C003CE997 /* TCChatCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TCChatCell.m; sourceTree = ""; }; + F668C880153E91210044DBAC /* SocketRocket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SocketRocket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + F6A12CCF145119B700C1D980 /* SRWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRWebSocket.h; sourceTree = ""; }; + F6A12CD0145119B700C1D980 /* SRWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRWebSocket.m; sourceTree = ""; }; + F6A12CD3145122FC00C1D980 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; + F6A12CD51451231B00C1D980 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; + F6B208301450F597009315AF /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + F6BDA802145900D200FE3253 /* SocketRocketTests-iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SocketRocketTests-iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 2D42275E1BB4358C000C1A6C /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 81C68D0E1D2CBFA800A1D005 /* libicucore.A.tbd in Frameworks */, + 81C68CD41D2CBE0A00A1D005 /* CFNetwork.framework in Frameworks */, + 2D4227831BB436B1000C1A6C /* Security.framework in Frameworks */, + 2D4227801BB43693000C1A6C /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 3345DC851C52ACD70083CCB8 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 81C68D071D2CBF6A00A1D005 /* libicucore.A.tbd in Frameworks */, + 81C68CDF1D2CBE1900A1D005 /* CFNetwork.framework in Frameworks */, + 3345DC871C52ACD70083CCB8 /* Security.framework in Frameworks */, + 3345DC881C52ACD70083CCB8 /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 81D647721D2CA78800690609 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 81D647741D2CA78800690609 /* Security.framework in Frameworks */, + 81D647751D2CA78800690609 /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + F62417E014D52F3C003CE997 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 81AFCD661D4C431C00B3AFC9 /* libicucore.tbd in Frameworks */, + F62417E614D52F3C003CE997 /* UIKit.framework in Frameworks */, + F62417E714D52F3C003CE997 /* Foundation.framework in Frameworks */, + F624180314D53449003CE997 /* CFNetwork.framework in Frameworks */, + F624180414D53449003CE997 /* Security.framework in Frameworks */, + 81E8A6A21D4C41E000916C7E /* SocketRocket.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + F668C87C153E91210044DBAC /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 81C68CEE1D2CBE9400A1D005 /* CFNetwork.framework in Frameworks */, + 81C68CF61D2CBED100A1D005 /* Security.framework in Frameworks */, + 81C68CF11D2CBE9F00A1D005 /* libicucore.tbd in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + F6BDA7FE145900D200FE3253 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 81D647B51D2CA8E200690609 /* SocketRocket.framework in Frameworks */, + F6BDA806145900D200FE3253 /* Foundation.framework in Frameworks */, + F6AE45241459071C0022AF3C /* CFNetwork.framework in Frameworks */, + F6016C8814620EC70037BB3D /* Security.framework in Frameworks */, + 81DCD1241D2D9235002501A2 /* libicucore.A.tbd in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 4861E7721D022211002FAB1D /* Proxy */ = { + isa = PBXGroup; + children = ( + 4861E7731D022211002FAB1D /* SRProxyConnect.h */, + 4861E7741D022211002FAB1D /* SRProxyConnect.m */, + ); + path = Proxy; + sourceTree = ""; + }; + 8105E4741CDD679A00AA12DB /* Tests */ = { + isa = PBXGroup; + children = ( + 8105E47A1CDD679A00AA12DB /* SRAutobahnTests.m */, + 8105E4751CDD679A00AA12DB /* Operations */, + 8105E47C1CDD679A00AA12DB /* Utilities */, + 8105E4781CDD679A00AA12DB /* Resources */, + ); + path = Tests; + sourceTree = ""; + }; + 8105E4751CDD679A00AA12DB /* Operations */ = { + isa = PBXGroup; + children = ( + 8105E4761CDD679A00AA12DB /* SRTWebSocketOperation.h */, + 8105E4771CDD679A00AA12DB /* SRTWebSocketOperation.m */, + 8105E4AC1CDD6E6200AA12DB /* SRAutobahnOperation.h */, + 8105E4AD1CDD6E6200AA12DB /* SRAutobahnOperation.m */, + ); + path = Operations; + sourceTree = ""; + }; + 8105E4781CDD679A00AA12DB /* Resources */ = { + isa = PBXGroup; + children = ( + 8105E5271CDD98E100AA12DB /* autobahn_configuration.json */, + 8105E4791CDD679A00AA12DB /* Info.plist */, + ); + path = Resources; + sourceTree = ""; + }; + 8105E47C1CDD679A00AA12DB /* Utilities */ = { + isa = PBXGroup; + children = ( + 8179967E1CE184F40084DA37 /* SRAutobahnUtilities.h */, + 8179967F1CE184F40084DA37 /* SRAutobahnUtilities.m */, + ); + path = Utilities; + sourceTree = ""; + }; + 811934B01CDAF711003AB243 /* Resources */ = { + isa = PBXGroup; + children = ( + 811934B11CDAF711003AB243 /* Info.plist */, + ); + path = Resources; + sourceTree = ""; + }; + 817995831CE139540084DA37 /* Delegate */ = { + isa = PBXGroup; + children = ( + 817995841CE139700084DA37 /* SRDelegateController.h */, + 817995851CE139700084DA37 /* SRDelegateController.m */, + ); + path = Delegate; + sourceTree = ""; + }; + 8186892C1D08EF3C004F94C8 /* Security */ = { + isa = PBXGroup; + children = ( + 454FEA791D2570D400073768 /* SRPinningSecurityPolicy.h */, + 454FEA7A1D2570D400073768 /* SRPinningSecurityPolicy.m */, + ); + path = Security; + sourceTree = ""; + }; + 81B31C0D1CDC404100D86D43 /* Internal */ = { + isa = PBXGroup; + children = ( + 8186892C1D08EF3C004F94C8 /* Security */, + 4861E7721D022211002FAB1D /* Proxy */, + 817995831CE139540084DA37 /* Delegate */, + 81B31C0E1CDC404100D86D43 /* IOConsumer */, + 81B31C5C1CDC443A00D86D43 /* RunLoop */, + 81B31C131CDC404100D86D43 /* Utilities */, + ); + path = Internal; + sourceTree = ""; + }; + 81B31C0E1CDC404100D86D43 /* IOConsumer */ = { + isa = PBXGroup; + children = ( + 81B31C0F1CDC404100D86D43 /* SRIOConsumer.h */, + 81B31C101CDC404100D86D43 /* SRIOConsumer.m */, + 81B31C111CDC404100D86D43 /* SRIOConsumerPool.h */, + 81B31C121CDC404100D86D43 /* SRIOConsumerPool.m */, + ); + path = IOConsumer; + sourceTree = ""; + }; + 81B31C131CDC404100D86D43 /* Utilities */ = { + isa = PBXGroup; + children = ( + 81B22EC31CE42D7E0073C636 /* SRError.h */, + 81B22EC41CE42D7E0073C636 /* SRError.m */, + 81B31C2B1CDC406B00D86D43 /* SRHash.h */, + 81B31C2C1CDC406B00D86D43 /* SRHash.m */, + 81C22BC01D124168007BFDDF /* SRHTTPConnectMessage.h */, + 81C22BC11D124168007BFDDF /* SRHTTPConnectMessage.m */, + 81900A4A1D18C9CC0015A290 /* SRLog.h */, + 81900A4B1D18C9CC0015A290 /* SRLog.m */, + 817491A61D1C8C33006E09DF /* SRMutex.h */, + 817491A71D1C8C33006E09DF /* SRMutex.m */, + 81C22BF61D1256E1007BFDDF /* SRRandom.h */, + 81C22BF71D1256E1007BFDDF /* SRRandom.m */, + 815FE7241D497D720085FDA5 /* SRConstants.h */, + 815FE7251D497D720085FDA5 /* SRConstants.m */, + 81B22EE21CE43ECC0073C636 /* SRURLUtilities.h */, + 81B22EE31CE43ECC0073C636 /* SRURLUtilities.m */, + F5391CBC1D2F4B4700606A81 /* SRSIMDHelpers.h */, + F5391CBD1D2F4B4700606A81 /* SRSIMDHelpers.m */, + ); + path = Utilities; + sourceTree = ""; + }; + 81B31C5C1CDC443A00D86D43 /* RunLoop */ = { + isa = PBXGroup; + children = ( + 81B31C5D1CDC444900D86D43 /* SRRunLoopThread.h */, + 81B31C5E1CDC444900D86D43 /* SRRunLoopThread.m */, + ); + name = RunLoop; + path = SocketRocket/Internal/RunLoop; + sourceTree = SOURCE_ROOT; + }; + 81C68CF41D2CBEBD00A1D005 /* macOS */ = { + isa = PBXGroup; + children = ( + F6B208301450F597009315AF /* Foundation.framework */, + F6A12CD3145122FC00C1D980 /* Security.framework */, + F6A12CD51451231B00C1D980 /* CFNetwork.framework */, + 81C68CF01D2CBE9F00A1D005 /* libicucore.tbd */, + ); + name = macOS; + sourceTree = ""; + }; + 81C68CFD1D2CBF1800A1D005 /* tvOS */ = { + isa = PBXGroup; + children = ( + 81C68CDE1D2CBE1900A1D005 /* CFNetwork.framework */, + 81C68D061D2CBF6A00A1D005 /* libicucore.A.tbd */, + ); + name = tvOS; + sourceTree = ""; + }; + 81C68CFE1D2CBF2100A1D005 /* iOS */ = { + isa = PBXGroup; + children = ( + F62417E514D52F3C003CE997 /* UIKit.framework */, + 81C68CD31D2CBE0A00A1D005 /* CFNetwork.framework */, + 81C68D0D1D2CBFA800A1D005 /* libicucore.A.tbd */, + ); + name = iOS; + sourceTree = ""; + }; + 81D647481D2CA6A100690609 /* Configurations */ = { + isa = PBXGroup; + children = ( + 81D6475A1D2CA6A100690609 /* SocketRocket-iOS.xcconfig */, + 81D647591D2CA6A100690609 /* SocketRocket-iOS-Dynamic.xcconfig */, + 81D6475B1D2CA6A100690609 /* SocketRocket-macOS.xcconfig */, + 81D6475C1D2CA6A100690609 /* SocketRocket-tvOS.xcconfig */, + 81D6475D1D2CA6A100690609 /* SocketRocketTests-iOS.xcconfig */, + 81E8A69A1D4C417A00916C7E /* TestChat-iOS.xcconfig */, + 81D647491D2CA6A100690609 /* Shared */, + ); + path = Configurations; + sourceTree = ""; + }; + 81D647491D2CA6A100690609 /* Shared */ = { + isa = PBXGroup; + children = ( + 81D6474A1D2CA6A100690609 /* Common.xcconfig */, + 81D6474B1D2CA6A100690609 /* Platform */, + 81D647501D2CA6A100690609 /* Product */, + 81D647551D2CA6A100690609 /* Project */, + 81D647581D2CA6A100690609 /* Warnings.xcconfig */, + ); + path = Shared; + sourceTree = ""; + }; + 81D6474B1D2CA6A100690609 /* Platform */ = { + isa = PBXGroup; + children = ( + 81D6474C1D2CA6A100690609 /* iOS.xcconfig */, + 81D6474D1D2CA6A100690609 /* macOS.xcconfig */, + 81D6474E1D2CA6A100690609 /* tvOS.xcconfig */, + 81D6474F1D2CA6A100690609 /* watchOS.xcconfig */, + ); + path = Platform; + sourceTree = ""; + }; + 81D647501D2CA6A100690609 /* Product */ = { + isa = PBXGroup; + children = ( + 81D647511D2CA6A100690609 /* Application.xcconfig */, + 81D647521D2CA6A100690609 /* DynamicFramework.xcconfig */, + 81D647531D2CA6A100690609 /* LogicTests.xcconfig */, + 81D647541D2CA6A100690609 /* StaticFramework.xcconfig */, + ); + path = Product; + sourceTree = ""; + }; + 81D647551D2CA6A100690609 /* Project */ = { + isa = PBXGroup; + children = ( + 81D647561D2CA6A100690609 /* Debug.xcconfig */, + 81D647571D2CA6A100690609 /* Release.xcconfig */, + ); + path = Project; + sourceTree = ""; + }; + F62417EA14D52F3C003CE997 /* TestChat */ = { + isa = PBXGroup; + children = ( + F62417EB14D52F3C003CE997 /* Supporting Files */, + F62417F314D52F3C003CE997 /* TCAppDelegate.h */, + F62417F414D52F3C003CE997 /* TCAppDelegate.m */, + F62417F614D52F3C003CE997 /* MainStoryboard.storyboard */, + F62417F914D52F3C003CE997 /* TCViewController.h */, + F62417FA14D52F3C003CE997 /* TCViewController.m */, + F62417FF14D5300C003CE997 /* TCChatCell.h */, + F624180014D5300C003CE997 /* TCChatCell.m */, + ); + path = TestChat; + sourceTree = ""; + }; + F62417EB14D52F3C003CE997 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + F61A0DC71625F44D00365EBD /* Default-568h@2x.png */, + F62417EC14D52F3C003CE997 /* TestChat-Info.plist */, + F62417ED14D52F3C003CE997 /* InfoPlist.strings */, + F62417F014D52F3C003CE997 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + F6B208221450F597009315AF = { + isa = PBXGroup; + children = ( + 81D647481D2CA6A100690609 /* Configurations */, + F6B208321450F597009315AF /* SocketRocket */, + 8105E4741CDD679A00AA12DB /* Tests */, + F62417EA14D52F3C003CE997 /* TestChat */, + F6B2082F1450F597009315AF /* Frameworks */, + F6B2082E1450F597009315AF /* Products */, + ); + indentWidth = 4; + sourceTree = ""; + tabWidth = 4; + }; + F6B2082E1450F597009315AF /* Products */ = { + isa = PBXGroup; + children = ( + F6BDA802145900D200FE3253 /* SocketRocketTests-iOS.xctest */, + F62417E314D52F3C003CE997 /* TestChat.app */, + F668C880153E91210044DBAC /* SocketRocket.framework */, + 2D4227621BB4358C000C1A6C /* SocketRocket.framework */, + 3345DC901C52ACD70083CCB8 /* SocketRocket.framework */, + 81D6478D1D2CA78800690609 /* SocketRocket.framework */, + ); + name = Products; + sourceTree = ""; + }; + F6B2082F1450F597009315AF /* Frameworks */ = { + isa = PBXGroup; + children = ( + 81AFCD651D4C431C00B3AFC9 /* libicucore.tbd */, + 81C68CF41D2CBEBD00A1D005 /* macOS */, + 81C68CFD1D2CBF1800A1D005 /* tvOS */, + 81C68CFE1D2CBF2100A1D005 /* iOS */, + ); + name = Frameworks; + sourceTree = ""; + }; + F6B208321450F597009315AF /* SocketRocket */ = { + isa = PBXGroup; + children = ( + 81B31C0D1CDC404100D86D43 /* Internal */, + 555E0EB11C51E56D00E6BB92 /* SocketRocket.h */, + 454A02D41D0FAD010060DFB2 /* SRSecurityPolicy.h */, + 454FEA831D25717C00073768 /* SRSecurityPolicy.m */, + F6A12CCF145119B700C1D980 /* SRWebSocket.h */, + F6A12CD0145119B700C1D980 /* SRWebSocket.m */, + 81CD05D51CEEC47300497F47 /* NSURLRequest+SRWebSocket.h */, + 8117C4221D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h */, + 81CD05D61CEEC47300497F47 /* NSURLRequest+SRWebSocket.m */, + 81CD05FB1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h */, + 8117C42F1D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h */, + 81CD05FC1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m */, + 811934B01CDAF711003AB243 /* Resources */, + ); + path = SocketRocket; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 2D42275F1BB4358C000C1A6C /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 81B22EE51CE43ECC0073C636 /* SRURLUtilities.h in Headers */, + 454FEA7F1D2570F800073768 /* SRPinningSecurityPolicy.h in Headers */, + 81B31C151CDC404100D86D43 /* SRIOConsumer.h in Headers */, + 8117C4241D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h in Headers */, + 81CD05FE1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h in Headers */, + 815FE7271D497D720085FDA5 /* SRConstants.h in Headers */, + 454A02D61D0FAD010060DFB2 /* SRSecurityPolicy.h in Headers */, + 81CD05D81CEEC47300497F47 /* NSURLRequest+SRWebSocket.h in Headers */, + 81900A4D1D18C9CC0015A290 /* SRLog.h in Headers */, + 81B31C1D1CDC404100D86D43 /* SRIOConsumerPool.h in Headers */, + 813364001D091E170062E28D /* SRProxyConnect.h in Headers */, + 2D42277F1BB4365C000C1A6C /* SRWebSocket.h in Headers */, + 81B31C2E1CDC406B00D86D43 /* SRHash.h in Headers */, + 811934BE1CDAF725003AB243 /* SocketRocket.h in Headers */, + 81C22BF91D1256E1007BFDDF /* SRRandom.h in Headers */, + 8117C4311D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h in Headers */, + 81C22BC31D124168007BFDDF /* SRHTTPConnectMessage.h in Headers */, + 817995871CE139700084DA37 /* SRDelegateController.h in Headers */, + 817491A91D1C8C33006E09DF /* SRMutex.h in Headers */, + 81B22EC61CE42D7E0073C636 /* SRError.h in Headers */, + 81B31C601CDC444900D86D43 /* SRRunLoopThread.h in Headers */, + F5391CBF1D2F4B4700606A81 /* SRSIMDHelpers.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 3345DC891C52ACD70083CCB8 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 81B22EE71CE43ECC0073C636 /* SRURLUtilities.h in Headers */, + 454FEA811D2570F900073768 /* SRPinningSecurityPolicy.h in Headers */, + 81B31C171CDC404100D86D43 /* SRIOConsumer.h in Headers */, + 8117C4261D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h in Headers */, + 81CD06001CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h in Headers */, + 815FE7291D497D720085FDA5 /* SRConstants.h in Headers */, + 454A02D81D0FAD010060DFB2 /* SRSecurityPolicy.h in Headers */, + 81CD05DA1CEEC47300497F47 /* NSURLRequest+SRWebSocket.h in Headers */, + 81900A4F1D18C9CC0015A290 /* SRLog.h in Headers */, + 81B31C1F1CDC404100D86D43 /* SRIOConsumerPool.h in Headers */, + 813364081D091E180062E28D /* SRProxyConnect.h in Headers */, + 3345DC8A1C52ACD70083CCB8 /* SRWebSocket.h in Headers */, + 81B31C301CDC406B00D86D43 /* SRHash.h in Headers */, + 811934C01CDAF726003AB243 /* SocketRocket.h in Headers */, + 81C22BFB1D1256E1007BFDDF /* SRRandom.h in Headers */, + 8117C4331D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h in Headers */, + 81C22BC51D124168007BFDDF /* SRHTTPConnectMessage.h in Headers */, + 817995891CE139700084DA37 /* SRDelegateController.h in Headers */, + 817491AB1D1C8C33006E09DF /* SRMutex.h in Headers */, + 81B22EC81CE42D7E0073C636 /* SRError.h in Headers */, + 81B31C621CDC444900D86D43 /* SRRunLoopThread.h in Headers */, + F5391CC11D2F4B4700606A81 /* SRSIMDHelpers.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 81D647761D2CA78800690609 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 81D647771D2CA78800690609 /* SRURLUtilities.h in Headers */, + 81D647781D2CA78800690609 /* SRPinningSecurityPolicy.h in Headers */, + 81D647791D2CA78800690609 /* SRIOConsumer.h in Headers */, + 8117C4231D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h in Headers */, + 81D6477A1D2CA78800690609 /* NSRunLoop+SRWebSocket.h in Headers */, + 815FE7261D497D720085FDA5 /* SRConstants.h in Headers */, + 81D6477B1D2CA78800690609 /* SRSecurityPolicy.h in Headers */, + 81D6477C1D2CA78800690609 /* NSURLRequest+SRWebSocket.h in Headers */, + 81D6477D1D2CA78800690609 /* SRLog.h in Headers */, + 81D6477E1D2CA78800690609 /* SRIOConsumerPool.h in Headers */, + 81D6477F1D2CA78800690609 /* SRProxyConnect.h in Headers */, + 81D647801D2CA78800690609 /* SRWebSocket.h in Headers */, + 81D647811D2CA78800690609 /* SRHash.h in Headers */, + 81D647821D2CA78800690609 /* SocketRocket.h in Headers */, + 81D647831D2CA78800690609 /* SRRandom.h in Headers */, + 8117C4301D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h in Headers */, + 81D647841D2CA78800690609 /* SRHTTPConnectMessage.h in Headers */, + 81D647851D2CA78800690609 /* SRDelegateController.h in Headers */, + 81D647861D2CA78800690609 /* SRMutex.h in Headers */, + 81D647871D2CA78800690609 /* SRError.h in Headers */, + 81D647881D2CA78800690609 /* SRRunLoopThread.h in Headers */, + F5391CBE1D2F4B4700606A81 /* SRSIMDHelpers.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + F668C87D153E91210044DBAC /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 81B22EE61CE43ECC0073C636 /* SRURLUtilities.h in Headers */, + 454FEA7D1D2570F600073768 /* SRPinningSecurityPolicy.h in Headers */, + 81B31C161CDC404100D86D43 /* SRIOConsumer.h in Headers */, + 8117C4251D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h in Headers */, + 81CD05FF1CEEC65D00497F47 /* NSRunLoop+SRWebSocket.h in Headers */, + 815FE7281D497D720085FDA5 /* SRConstants.h in Headers */, + 454A02D71D0FAD010060DFB2 /* SRSecurityPolicy.h in Headers */, + 81CD05D91CEEC47300497F47 /* NSURLRequest+SRWebSocket.h in Headers */, + 81900A4E1D18C9CC0015A290 /* SRLog.h in Headers */, + 81B31C1E1CDC404100D86D43 /* SRIOConsumerPool.h in Headers */, + 813364041D091E170062E28D /* SRProxyConnect.h in Headers */, + F668C8AA153E92F90044DBAC /* SRWebSocket.h in Headers */, + 81B31C2F1CDC406B00D86D43 /* SRHash.h in Headers */, + 811934BC1CDAF725003AB243 /* SocketRocket.h in Headers */, + 81C22BFA1D1256E1007BFDDF /* SRRandom.h in Headers */, + 8117C4321D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h in Headers */, + 81C22BC41D124168007BFDDF /* SRHTTPConnectMessage.h in Headers */, + 817995881CE139700084DA37 /* SRDelegateController.h in Headers */, + 817491AA1D1C8C33006E09DF /* SRMutex.h in Headers */, + 81B22EC71CE42D7E0073C636 /* SRError.h in Headers */, + 81B31C611CDC444900D86D43 /* SRRunLoopThread.h in Headers */, + F5391CC01D2F4B4700606A81 /* SRSIMDHelpers.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 2D4227611BB4358C000C1A6C /* SocketRocket-iOS-Dynamic */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2D4227671BB4358C000C1A6C /* Build configuration list for PBXNativeTarget "SocketRocket-iOS-Dynamic" */; + buildPhases = ( + 2D42275D1BB4358C000C1A6C /* Sources */, + 2D42275E1BB4358C000C1A6C /* Frameworks */, + 2D42275F1BB4358C000C1A6C /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "SocketRocket-iOS-Dynamic"; + productName = "SocketRocket-iOS"; + productReference = 2D4227621BB4358C000C1A6C /* SocketRocket.framework */; + productType = "com.apple.product-type.framework"; + }; + 3345DC821C52ACD70083CCB8 /* SocketRocket-tvOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = 3345DC8D1C52ACD70083CCB8 /* Build configuration list for PBXNativeTarget "SocketRocket-tvOS" */; + buildPhases = ( + 3345DC831C52ACD70083CCB8 /* Sources */, + 3345DC851C52ACD70083CCB8 /* Frameworks */, + 3345DC891C52ACD70083CCB8 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "SocketRocket-tvOS"; + productName = "SocketRocket-iOS"; + productReference = 3345DC901C52ACD70083CCB8 /* SocketRocket.framework */; + productType = "com.apple.product-type.framework"; + }; + 81D6475F1D2CA78800690609 /* SocketRocket-iOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = 81D6478A1D2CA78800690609 /* Build configuration list for PBXNativeTarget "SocketRocket-iOS" */; + buildPhases = ( + 81D647601D2CA78800690609 /* Sources */, + 81D647721D2CA78800690609 /* Frameworks */, + 81D647761D2CA78800690609 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "SocketRocket-iOS"; + productName = "SocketRocket-iOS"; + productReference = 81D6478D1D2CA78800690609 /* SocketRocket.framework */; + productType = "com.apple.product-type.framework"; + }; + F62417E214D52F3C003CE997 /* TestChat */ = { + isa = PBXNativeTarget; + buildConfigurationList = F62417FC14D52F3C003CE997 /* Build configuration list for PBXNativeTarget "TestChat" */; + buildPhases = ( + F62417DF14D52F3C003CE997 /* Sources */, + F62417E014D52F3C003CE997 /* Frameworks */, + F62417E114D52F3C003CE997 /* Resources */, + 81E8A6A61D4C41E000916C7E /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + 81E8A6A11D4C41DA00916C7E /* PBXTargetDependency */, + 81E8A6A51D4C41E000916C7E /* PBXTargetDependency */, + ); + name = TestChat; + productName = TestChat; + productReference = F62417E314D52F3C003CE997 /* TestChat.app */; + productType = "com.apple.product-type.application"; + }; + F668C87F153E91210044DBAC /* SocketRocket-macOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = F668C891153E91210044DBAC /* Build configuration list for PBXNativeTarget "SocketRocket-macOS" */; + buildPhases = ( + F6396B85153E67EC00345B5E /* Sources */, + F668C87C153E91210044DBAC /* Frameworks */, + F668C87D153E91210044DBAC /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "SocketRocket-macOS"; + productName = SocketRocketOSX; + productReference = F668C880153E91210044DBAC /* SocketRocket.framework */; + productType = "com.apple.product-type.framework"; + }; + F6BDA801145900D200FE3253 /* SocketRocketTests-iOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = F6BDA813145900D200FE3253 /* Build configuration list for PBXNativeTarget "SocketRocketTests-iOS" */; + buildPhases = ( + F6BDA7FD145900D200FE3253 /* Sources */, + F6BDA7FE145900D200FE3253 /* Frameworks */, + F6BDA7FF145900D200FE3253 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 81D647B41D2CA8DD00690609 /* PBXTargetDependency */, + ); + name = "SocketRocketTests-iOS"; + productName = SRWebSocketTests; + productReference = F6BDA802145900D200FE3253 /* SocketRocketTests-iOS.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + F6B208241450F597009315AF /* Project object */ = { + isa = PBXProject; + attributes = { + LastTestingUpgradeCheck = 0640; + LastUpgradeCheck = 0800; + }; + buildConfigurationList = F6B208271450F597009315AF /* Build configuration list for PBXProject "SocketRocket" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = F6B208221450F597009315AF; + productRefGroup = F6B2082E1450F597009315AF /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 81D6475F1D2CA78800690609 /* SocketRocket-iOS */, + 2D4227611BB4358C000C1A6C /* SocketRocket-iOS-Dynamic */, + F668C87F153E91210044DBAC /* SocketRocket-macOS */, + 3345DC821C52ACD70083CCB8 /* SocketRocket-tvOS */, + F6BDA801145900D200FE3253 /* SocketRocketTests-iOS */, + F62417E214D52F3C003CE997 /* TestChat */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + F62417E114D52F3C003CE997 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + F62417EF14D52F3C003CE997 /* InfoPlist.strings in Resources */, + F62417F814D52F3C003CE997 /* MainStoryboard.storyboard in Resources */, + F61A0DC81625F44D00365EBD /* Default-568h@2x.png in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + F6BDA7FF145900D200FE3253 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8105E5281CDD98E100AA12DB /* autobahn_configuration.json in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 2D42275D1BB4358C000C1A6C /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 81CD05DC1CEEC47300497F47 /* NSURLRequest+SRWebSocket.m in Sources */, + F5391CC31D2F4B4700606A81 /* SRSIMDHelpers.m in Sources */, + 81B22ECA1CE42D7E0073C636 /* SRError.m in Sources */, + 81B31C191CDC404100D86D43 /* SRIOConsumer.m in Sources */, + 81C22BC71D124168007BFDDF /* SRHTTPConnectMessage.m in Sources */, + 454FEA801D2570F800073768 /* SRPinningSecurityPolicy.m in Sources */, + 454FEA851D25719900073768 /* SRSecurityPolicy.m in Sources */, + 815FE72B1D497D720085FDA5 /* SRConstants.m in Sources */, + 81CD06021CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m in Sources */, + 2D4227851BB43734000C1A6C /* SRWebSocket.m in Sources */, + 81C22BFD1D1256E1007BFDDF /* SRRandom.m in Sources */, + 81B31C211CDC404100D86D43 /* SRIOConsumerPool.m in Sources */, + 81B22EE91CE43ECC0073C636 /* SRURLUtilities.m in Sources */, + 8133640C1D091E1B0062E28D /* SRProxyConnect.m in Sources */, + 817491AD1D1C8C33006E09DF /* SRMutex.m in Sources */, + 81B31C641CDC444900D86D43 /* SRRunLoopThread.m in Sources */, + 81900A511D18C9CC0015A290 /* SRLog.m in Sources */, + 81B31C321CDC406B00D86D43 /* SRHash.m in Sources */, + 8179958B1CE139700084DA37 /* SRDelegateController.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 3345DC831C52ACD70083CCB8 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 81CD05DE1CEEC47300497F47 /* NSURLRequest+SRWebSocket.m in Sources */, + F5391CC51D2F4B4700606A81 /* SRSIMDHelpers.m in Sources */, + 81B22ECC1CE42D7E0073C636 /* SRError.m in Sources */, + 81B31C1B1CDC404100D86D43 /* SRIOConsumer.m in Sources */, + 81C22BC91D124168007BFDDF /* SRHTTPConnectMessage.m in Sources */, + 454FEA821D2570F900073768 /* SRPinningSecurityPolicy.m in Sources */, + 454FEA871D25719A00073768 /* SRSecurityPolicy.m in Sources */, + 815FE72D1D497D720085FDA5 /* SRConstants.m in Sources */, + 81CD06041CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m in Sources */, + 3345DC841C52ACD70083CCB8 /* SRWebSocket.m in Sources */, + 81C22BFF1D1256E1007BFDDF /* SRRandom.m in Sources */, + 81B31C231CDC404100D86D43 /* SRIOConsumerPool.m in Sources */, + 81B22EEB1CE43ECC0073C636 /* SRURLUtilities.m in Sources */, + 8133640F1D091E1C0062E28D /* SRProxyConnect.m in Sources */, + 817491AF1D1C8C33006E09DF /* SRMutex.m in Sources */, + 81B31C661CDC444900D86D43 /* SRRunLoopThread.m in Sources */, + 81900A531D18C9CC0015A290 /* SRLog.m in Sources */, + 81B31C341CDC406B00D86D43 /* SRHash.m in Sources */, + 8179958D1CE139700084DA37 /* SRDelegateController.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 81D647601D2CA78800690609 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 81D647611D2CA78800690609 /* NSURLRequest+SRWebSocket.m in Sources */, + F5391CC21D2F4B4700606A81 /* SRSIMDHelpers.m in Sources */, + 81D647621D2CA78800690609 /* SRError.m in Sources */, + 81D647631D2CA78800690609 /* SRIOConsumer.m in Sources */, + 81D647641D2CA78800690609 /* SRHTTPConnectMessage.m in Sources */, + 81D647651D2CA78800690609 /* SRPinningSecurityPolicy.m in Sources */, + 81D647661D2CA78800690609 /* SRSecurityPolicy.m in Sources */, + 815FE72A1D497D720085FDA5 /* SRConstants.m in Sources */, + 81D647671D2CA78800690609 /* NSRunLoop+SRWebSocket.m in Sources */, + 81D647681D2CA78800690609 /* SRWebSocket.m in Sources */, + 81D647691D2CA78800690609 /* SRRandom.m in Sources */, + 81D6476A1D2CA78800690609 /* SRIOConsumerPool.m in Sources */, + 81D6476B1D2CA78800690609 /* SRURLUtilities.m in Sources */, + 81D6476C1D2CA78800690609 /* SRProxyConnect.m in Sources */, + 81D6476D1D2CA78800690609 /* SRMutex.m in Sources */, + 81D6476E1D2CA78800690609 /* SRRunLoopThread.m in Sources */, + 81D6476F1D2CA78800690609 /* SRLog.m in Sources */, + 81D647701D2CA78800690609 /* SRHash.m in Sources */, + 81D647711D2CA78800690609 /* SRDelegateController.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + F62417DF14D52F3C003CE997 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + F62417F114D52F3C003CE997 /* main.m in Sources */, + F62417F514D52F3C003CE997 /* TCAppDelegate.m in Sources */, + F62417FB14D52F3C003CE997 /* TCViewController.m in Sources */, + F624180114D5300C003CE997 /* TCChatCell.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + F6396B85153E67EC00345B5E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 81CD05DD1CEEC47300497F47 /* NSURLRequest+SRWebSocket.m in Sources */, + F5391CC41D2F4B4700606A81 /* SRSIMDHelpers.m in Sources */, + 81B22ECB1CE42D7E0073C636 /* SRError.m in Sources */, + 81B31C1A1CDC404100D86D43 /* SRIOConsumer.m in Sources */, + 81C22BC81D124168007BFDDF /* SRHTTPConnectMessage.m in Sources */, + 454FEA7E1D2570F600073768 /* SRPinningSecurityPolicy.m in Sources */, + 454FEA861D25719A00073768 /* SRSecurityPolicy.m in Sources */, + 815FE72C1D497D720085FDA5 /* SRConstants.m in Sources */, + 81CD06031CEEC65D00497F47 /* NSRunLoop+SRWebSocket.m in Sources */, + F6396B86153E67EC00345B5E /* SRWebSocket.m in Sources */, + 81C22BFE1D1256E1007BFDDF /* SRRandom.m in Sources */, + 81B31C221CDC404100D86D43 /* SRIOConsumerPool.m in Sources */, + 81B22EEA1CE43ECC0073C636 /* SRURLUtilities.m in Sources */, + 8133640E1D091E1B0062E28D /* SRProxyConnect.m in Sources */, + 817491AE1D1C8C33006E09DF /* SRMutex.m in Sources */, + 81B31C651CDC444900D86D43 /* SRRunLoopThread.m in Sources */, + 81900A521D18C9CC0015A290 /* SRLog.m in Sources */, + 81B31C331CDC406B00D86D43 /* SRHash.m in Sources */, + 8179958C1CE139700084DA37 /* SRDelegateController.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + F6BDA7FD145900D200FE3253 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8105E4AE1CDD6E6200AA12DB /* SRAutobahnOperation.m in Sources */, + 817996801CE184F40084DA37 /* SRAutobahnUtilities.m in Sources */, + 8105E4801CDD67B400AA12DB /* SRAutobahnTests.m in Sources */, + 8105E4821CDD67BD00AA12DB /* SRTWebSocketOperation.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 81D647B41D2CA8DD00690609 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 81D6475F1D2CA78800690609 /* SocketRocket-iOS */; + targetProxy = 81D647B31D2CA8DD00690609 /* PBXContainerItemProxy */; + }; + 81E8A6A11D4C41DA00916C7E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 2D4227611BB4358C000C1A6C /* SocketRocket-iOS-Dynamic */; + targetProxy = 81E8A6A01D4C41DA00916C7E /* PBXContainerItemProxy */; + }; + 81E8A6A51D4C41E000916C7E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 81D6475F1D2CA78800690609 /* SocketRocket-iOS */; + targetProxy = 81E8A6A41D4C41E000916C7E /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + F62417ED14D52F3C003CE997 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + F62417EE14D52F3C003CE997 /* en */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; + F62417F614D52F3C003CE997 /* MainStoryboard.storyboard */ = { + isa = PBXVariantGroup; + children = ( + F62417F714D52F3C003CE997 /* en */, + ); + name = MainStoryboard.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 2D4227681BB4358C000C1A6C /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D647591D2CA6A100690609 /* SocketRocket-iOS-Dynamic.xcconfig */; + buildSettings = { + MTL_ENABLE_DEBUG_INFO = YES; + }; + name = Debug; + }; + 2D4227691BB4358C000C1A6C /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D647591D2CA6A100690609 /* SocketRocket-iOS-Dynamic.xcconfig */; + buildSettings = { + MTL_ENABLE_DEBUG_INFO = NO; + }; + name = Release; + }; + 3345DC8E1C52ACD70083CCB8 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D6475C1D2CA6A100690609 /* SocketRocket-tvOS.xcconfig */; + buildSettings = { + MTL_ENABLE_DEBUG_INFO = YES; + TARGETED_DEVICE_FAMILY = 3; + }; + name = Debug; + }; + 3345DC8F1C52ACD70083CCB8 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D6475C1D2CA6A100690609 /* SocketRocket-tvOS.xcconfig */; + buildSettings = { + MTL_ENABLE_DEBUG_INFO = NO; + TARGETED_DEVICE_FAMILY = 3; + }; + name = Release; + }; + 81D6478B1D2CA78800690609 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D6475A1D2CA6A100690609 /* SocketRocket-iOS.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + 81D6478C1D2CA78800690609 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D6475A1D2CA6A100690609 /* SocketRocket-iOS.xcconfig */; + buildSettings = { + }; + name = Release; + }; + F62417FD14D52F3C003CE997 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81E8A69A1D4C417A00916C7E /* TestChat-iOS.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + F62417FE14D52F3C003CE997 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81E8A69A1D4C417A00916C7E /* TestChat-iOS.xcconfig */; + buildSettings = { + }; + name = Release; + }; + F668C892153E91210044DBAC /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D6475B1D2CA6A100690609 /* SocketRocket-macOS.xcconfig */; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + }; + name = Debug; + }; + F668C893153E91210044DBAC /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D6475B1D2CA6A100690609 /* SocketRocket-macOS.xcconfig */; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + }; + name = Release; + }; + F6B208381450F597009315AF /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D647561D2CA6A100690609 /* Debug.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + F6B208391450F597009315AF /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D647571D2CA6A100690609 /* Release.xcconfig */; + buildSettings = { + }; + name = Release; + }; + F6BDA811145900D200FE3253 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D6475D1D2CA6A100690609 /* SocketRocketTests-iOS.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + F6BDA812145900D200FE3253 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 81D6475D1D2CA6A100690609 /* SocketRocketTests-iOS.xcconfig */; + buildSettings = { + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 2D4227671BB4358C000C1A6C /* Build configuration list for PBXNativeTarget "SocketRocket-iOS-Dynamic" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2D4227681BB4358C000C1A6C /* Debug */, + 2D4227691BB4358C000C1A6C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 3345DC8D1C52ACD70083CCB8 /* Build configuration list for PBXNativeTarget "SocketRocket-tvOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3345DC8E1C52ACD70083CCB8 /* Debug */, + 3345DC8F1C52ACD70083CCB8 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 81D6478A1D2CA78800690609 /* Build configuration list for PBXNativeTarget "SocketRocket-iOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 81D6478B1D2CA78800690609 /* Debug */, + 81D6478C1D2CA78800690609 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + F62417FC14D52F3C003CE997 /* Build configuration list for PBXNativeTarget "TestChat" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + F62417FD14D52F3C003CE997 /* Debug */, + F62417FE14D52F3C003CE997 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + F668C891153E91210044DBAC /* Build configuration list for PBXNativeTarget "SocketRocket-macOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + F668C892153E91210044DBAC /* Debug */, + F668C893153E91210044DBAC /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + F6B208271450F597009315AF /* Build configuration list for PBXProject "SocketRocket" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + F6B208381450F597009315AF /* Debug */, + F6B208391450F597009315AF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + F6BDA813145900D200FE3253 /* Build configuration list for PBXNativeTarget "SocketRocketTests-iOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + F6BDA811145900D200FE3253 /* Debug */, + F6BDA812145900D200FE3253 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = F6B208241450F597009315AF /* Project object */; +} diff --git a/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100755 index 0000000..998c1c0 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100755 index 0000000..08de0be --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded + + + diff --git a/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-iOS-Dynamic.xcscheme b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-iOS-Dynamic.xcscheme new file mode 100755 index 0000000..ab26139 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-iOS-Dynamic.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-iOS.xcscheme b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-iOS.xcscheme new file mode 100755 index 0000000..5565f08 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-iOS.xcscheme @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-macOS.xcscheme b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-macOS.xcscheme new file mode 100755 index 0000000..1408491 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-macOS.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-tvOS.xcscheme b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-tvOS.xcscheme new file mode 100755 index 0000000..6ef9ee9 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-tvOS.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocketTests.xcscheme b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocketTests.xcscheme new file mode 100755 index 0000000..0610291 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocketTests.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/TestChat.xcscheme b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/TestChat.xcscheme new file mode 100755 index 0000000..9c2f485 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket.xcodeproj/xcshareddata/xcschemes/TestChat.xcscheme @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Delegate/SRDelegateController.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Delegate/SRDelegateController.h new file mode 100755 index 0000000..0004a01 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Delegate/SRDelegateController.h @@ -0,0 +1,67 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +#import + +NS_ASSUME_NONNULL_BEGIN + +#if OBJC_BOOL_IS_BOOL + +struct SRDelegateAvailableMethods { + BOOL didReceiveMessage : 1; + BOOL didReceiveMessageWithString : 1; + BOOL didReceiveMessageWithData : 1; + BOOL didOpen : 1; + BOOL didFailWithError : 1; + BOOL didCloseWithCode : 1; + BOOL didReceivePing : 1; + BOOL didReceivePong : 1; + BOOL shouldConvertTextFrameToString : 1; +}; + +#else + +struct SRDelegateAvailableMethods { + BOOL didReceiveMessage; + BOOL didReceiveMessageWithString; + BOOL didReceiveMessageWithData; + BOOL didOpen; + BOOL didFailWithError; + BOOL didCloseWithCode; + BOOL didReceivePing; + BOOL didReceivePong; + BOOL shouldConvertTextFrameToString; +}; + +#endif + +typedef struct SRDelegateAvailableMethods SRDelegateAvailableMethods; + +typedef void(^SRDelegateBlock)(id _Nullable delegate, SRDelegateAvailableMethods availableMethods); + +@interface SRDelegateController : NSObject + +@property (nonatomic, weak) id delegate; +@property (atomic, readonly) SRDelegateAvailableMethods availableDelegateMethods; + +@property (nullable, nonatomic, strong) dispatch_queue_t dispatchQueue; +@property (nullable, nonatomic, strong) NSOperationQueue *operationQueue; + +///-------------------------------------- +#pragma mark - Perform +///-------------------------------------- + +- (void)performDelegateBlock:(SRDelegateBlock)block; +- (void)performDelegateQueueBlock:(dispatch_block_t)block; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Delegate/SRDelegateController.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Delegate/SRDelegateController.m new file mode 100755 index 0000000..69642d4 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Delegate/SRDelegateController.m @@ -0,0 +1,138 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRDelegateController.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SRDelegateController () + +@property (nonatomic, strong, readonly) dispatch_queue_t accessQueue; + +@property (atomic, assign, readwrite) SRDelegateAvailableMethods availableDelegateMethods; + +@end + +@implementation SRDelegateController + +@synthesize delegate = _delegate; +@synthesize dispatchQueue = _dispatchQueue; +@synthesize operationQueue = _operationQueue; + +///-------------------------------------- +#pragma mark - Init +///-------------------------------------- + +- (instancetype)init +{ + self = [super init]; + if (!self) return self; + + _accessQueue = dispatch_queue_create("com.facebook.socketrocket.delegate.access", DISPATCH_QUEUE_CONCURRENT); + _dispatchQueue = dispatch_get_main_queue(); + + return self; +} + +///-------------------------------------- +#pragma mark - Accessors +///-------------------------------------- + +- (void)setDelegate:(id _Nullable)delegate +{ + dispatch_barrier_async(self.accessQueue, ^{ + _delegate = delegate; + + self.availableDelegateMethods = (SRDelegateAvailableMethods){ + .didReceiveMessage = [delegate respondsToSelector:@selector(webSocket:didReceiveMessage:)], + .didReceiveMessageWithString = [delegate respondsToSelector:@selector(webSocket:didReceiveMessageWithString:)], + .didReceiveMessageWithData = [delegate respondsToSelector:@selector(webSocket:didReceiveMessageWithData:)], + .didOpen = [delegate respondsToSelector:@selector(webSocketDidOpen:)], + .didFailWithError = [delegate respondsToSelector:@selector(webSocket:didFailWithError:)], + .didCloseWithCode = [delegate respondsToSelector:@selector(webSocket:didCloseWithCode:reason:wasClean:)], + .didReceivePing = [delegate respondsToSelector:@selector(webSocket:didReceivePingWithData:)], + .didReceivePong = [delegate respondsToSelector:@selector(webSocket:didReceivePong:)], + .shouldConvertTextFrameToString = [delegate respondsToSelector:@selector(webSocketShouldConvertTextFrameToString:)] + }; + }); +} + +- (id _Nullable)delegate +{ + __block id delegate = nil; + dispatch_sync(self.accessQueue, ^{ + delegate = _delegate; + }); + return delegate; +} + +- (void)setDispatchQueue:(dispatch_queue_t _Nullable)queue +{ + dispatch_barrier_async(self.accessQueue, ^{ + _dispatchQueue = queue ?: dispatch_get_main_queue(); + _operationQueue = nil; + }); +} + +- (dispatch_queue_t _Nullable)dispatchQueue +{ + __block dispatch_queue_t queue = nil; + dispatch_sync(self.accessQueue, ^{ + queue = _dispatchQueue; + }); + return queue; +} + +- (void)setOperationQueue:(NSOperationQueue *_Nullable)queue +{ + dispatch_barrier_async(self.accessQueue, ^{ + _dispatchQueue = queue ? nil : dispatch_get_main_queue(); + _operationQueue = queue; + }); +} + +- (NSOperationQueue *_Nullable)operationQueue +{ + __block NSOperationQueue *queue = nil; + dispatch_sync(self.accessQueue, ^{ + queue = _operationQueue; + }); + return queue; +} + +///-------------------------------------- +#pragma mark - Perform +///-------------------------------------- + +- (void)performDelegateBlock:(SRDelegateBlock)block +{ + __block __strong id delegate = nil; + __block SRDelegateAvailableMethods availableMethods = {}; + dispatch_sync(self.accessQueue, ^{ + delegate = _delegate; // Not `OK` to go through `self`, since queue sync. + availableMethods = self.availableDelegateMethods; // `OK` to call through `self`, since no queue sync. + }); + [self performDelegateQueueBlock:^{ + block(delegate, availableMethods); + }]; +} + +- (void)performDelegateQueueBlock:(dispatch_block_t)block +{ + dispatch_queue_t dispatchQueue = self.dispatchQueue; + if (dispatchQueue) { + dispatch_async(dispatchQueue, block); + } else { + [self.operationQueue addOperationWithBlock:block]; + } +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumer.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumer.h new file mode 100755 index 0000000..855eef2 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumer.h @@ -0,0 +1,40 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +@class SRWebSocket; // TODO: (nlutsenko) Remove dependency on SRWebSocket here. + +// Returns number of bytes consumed. Returning 0 means you didn't match. +// Sends bytes to callback handler; +typedef size_t (^stream_scanner)(NSData *collected_data); +typedef void (^data_callback)(SRWebSocket *webSocket, NSData *data); + +@interface SRIOConsumer : NSObject { + stream_scanner _scanner; + data_callback _handler; + size_t _bytesNeeded; + BOOL _readToCurrentFrame; + BOOL _unmaskBytes; +} +@property (nonatomic, copy, readonly) stream_scanner consumer; +@property (nonatomic, copy, readonly) data_callback handler; +@property (nonatomic, assign) size_t bytesNeeded; +@property (nonatomic, assign, readonly) BOOL readToCurrentFrame; +@property (nonatomic, assign, readonly) BOOL unmaskBytes; + +- (void)resetWithScanner:(stream_scanner)scanner + handler:(data_callback)handler + bytesNeeded:(size_t)bytesNeeded + readToCurrentFrame:(BOOL)readToCurrentFrame + unmaskBytes:(BOOL)unmaskBytes; + +@end diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumer.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumer.m new file mode 100755 index 0000000..c731b95 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumer.m @@ -0,0 +1,36 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRIOConsumer.h" + +@implementation SRIOConsumer + +@synthesize bytesNeeded = _bytesNeeded; +@synthesize consumer = _scanner; +@synthesize handler = _handler; +@synthesize readToCurrentFrame = _readToCurrentFrame; +@synthesize unmaskBytes = _unmaskBytes; + +- (void)resetWithScanner:(stream_scanner)scanner + handler:(data_callback)handler + bytesNeeded:(size_t)bytesNeeded + readToCurrentFrame:(BOOL)readToCurrentFrame + unmaskBytes:(BOOL)unmaskBytes +{ + _scanner = [scanner copy]; + _handler = [handler copy]; + _bytesNeeded = bytesNeeded; + _readToCurrentFrame = readToCurrentFrame; + _unmaskBytes = unmaskBytes; + assert(_scanner || _bytesNeeded); +} + +@end diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumerPool.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumerPool.h new file mode 100755 index 0000000..37bd24c --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumerPool.h @@ -0,0 +1,28 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +#import "SRIOConsumer.h" // TODO: (nlutsenko) Convert to @class and constants file for block types + +// This class is not thread-safe, and is expected to always be run on the same queue. +@interface SRIOConsumerPool : NSObject + +- (instancetype)initWithBufferCapacity:(NSUInteger)poolSize; + +- (SRIOConsumer *)consumerWithScanner:(stream_scanner)scanner + handler:(data_callback)handler + bytesNeeded:(size_t)bytesNeeded + readToCurrentFrame:(BOOL)readToCurrentFrame + unmaskBytes:(BOOL)unmaskBytes; +- (void)returnConsumer:(SRIOConsumer *)consumer; + +@end diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumerPool.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumerPool.m new file mode 100755 index 0000000..d8aab6f --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/IOConsumer/SRIOConsumerPool.m @@ -0,0 +1,64 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRIOConsumerPool.h" + +@implementation SRIOConsumerPool { + NSUInteger _poolSize; + NSMutableArray *_bufferedConsumers; +} + +- (instancetype)initWithBufferCapacity:(NSUInteger)poolSize; +{ + self = [super init]; + if (self) { + _poolSize = poolSize; + _bufferedConsumers = [NSMutableArray arrayWithCapacity:poolSize]; + } + return self; +} + +- (instancetype)init +{ + return [self initWithBufferCapacity:8]; +} + +- (SRIOConsumer *)consumerWithScanner:(stream_scanner)scanner + handler:(data_callback)handler + bytesNeeded:(size_t)bytesNeeded + readToCurrentFrame:(BOOL)readToCurrentFrame + unmaskBytes:(BOOL)unmaskBytes +{ + SRIOConsumer *consumer = nil; + if (_bufferedConsumers.count) { + consumer = [_bufferedConsumers lastObject]; + [_bufferedConsumers removeLastObject]; + } else { + consumer = [[SRIOConsumer alloc] init]; + } + + [consumer resetWithScanner:scanner + handler:handler + bytesNeeded:bytesNeeded + readToCurrentFrame:readToCurrentFrame + unmaskBytes:unmaskBytes]; + + return consumer; +} + +- (void)returnConsumer:(SRIOConsumer *)consumer; +{ + if (_bufferedConsumers.count < _poolSize) { + [_bufferedConsumers addObject:consumer]; + } +} + +@end diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/NSRunLoop+SRWebSocketPrivate.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/NSRunLoop+SRWebSocketPrivate.h new file mode 100755 index 0000000..098f7a8 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/NSRunLoop+SRWebSocketPrivate.h @@ -0,0 +1,13 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +// Empty function that force links the object file for the category. +extern void import_NSRunLoop_SRWebSocket(void); diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/NSURLRequest+SRWebSocketPrivate.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/NSURLRequest+SRWebSocketPrivate.h new file mode 100755 index 0000000..b09dde4 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/NSURLRequest+SRWebSocketPrivate.h @@ -0,0 +1,13 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +// Empty function that force links the object file for the category. +extern void import_NSURLRequest_SRWebSocket(void); diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Proxy/SRProxyConnect.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Proxy/SRProxyConnect.h new file mode 100755 index 0000000..ed17d39 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Proxy/SRProxyConnect.h @@ -0,0 +1,26 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +typedef void(^SRProxyConnectCompletion)(NSError *_Nullable error, + NSInputStream *_Nullable readStream, + NSOutputStream *_Nullable writeStream); + +@interface SRProxyConnect : NSObject + +- (instancetype)initWithURL:(NSURL *)url; + +- (void)openNetworkStreamWithCompletion:(SRProxyConnectCompletion)completion; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Proxy/SRProxyConnect.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Proxy/SRProxyConnect.m new file mode 100755 index 0000000..aa119a7 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Proxy/SRProxyConnect.m @@ -0,0 +1,481 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRProxyConnect.h" + +#import "NSRunLoop+SRWebSocket.h" +#import "SRConstants.h" +#import "SRError.h" +#import "SRLog.h" +#import "SRURLUtilities.h" + +@interface SRProxyConnect() + +@property (nonatomic, strong) NSURL *url; +@property (nonatomic, strong) NSInputStream *inputStream; +@property (nonatomic, strong) NSOutputStream *outputStream; + +@end + +@implementation SRProxyConnect +{ + SRProxyConnectCompletion _completion; + + NSString *_httpProxyHost; + uint32_t _httpProxyPort; + + CFHTTPMessageRef _receivedHTTPHeaders; + + NSString *_socksProxyHost; + uint32_t _socksProxyPort; + NSString *_socksProxyUsername; + NSString *_socksProxyPassword; + + BOOL _connectionRequiresSSL; + + NSMutableArray *_inputQueue; + dispatch_queue_t _writeQueue; +} + +///-------------------------------------- +#pragma mark - Init +///-------------------------------------- + +-(instancetype)initWithURL:(NSURL *)url +{ + self = [super init]; + if (!self) return self; + + _url = url; + _connectionRequiresSSL = SRURLRequiresSSL(url); + + _writeQueue = dispatch_queue_create("com.facebook.socketrocket.proxyconnect.write", DISPATCH_QUEUE_SERIAL); + _inputQueue = [NSMutableArray arrayWithCapacity:2]; + + return self; +} + +- (void)dealloc +{ + // If we get deallocated before the socket open finishes - we need to cleanup everything. + + [self.inputStream removeFromRunLoop:[NSRunLoop SR_networkRunLoop] forMode:NSDefaultRunLoopMode]; + self.inputStream.delegate = nil; + [self.inputStream close]; + self.inputStream = nil; + + self.outputStream.delegate = nil; + [self.outputStream close]; + self.outputStream = nil; +} + +///-------------------------------------- +#pragma mark - Open +///-------------------------------------- + +- (void)openNetworkStreamWithCompletion:(SRProxyConnectCompletion)completion +{ + _completion = completion; + [self _configureProxy]; +} + +///-------------------------------------- +#pragma mark - Flow +///-------------------------------------- + +- (void)_didConnect +{ + SRDebugLog(@"_didConnect, return streams"); + if (_connectionRequiresSSL) { + if (_httpProxyHost) { + // Must set the real peer name before turning on SSL + SRDebugLog(@"proxy set peer name to real host %@", self.url.host); + [self.outputStream setProperty:self.url.host forKey:@"_kCFStreamPropertySocketPeerName"]; + } + } + if (_receivedHTTPHeaders) { + CFRelease(_receivedHTTPHeaders); + _receivedHTTPHeaders = NULL; + } + + NSInputStream *inputStream = self.inputStream; + NSOutputStream *outputStream = self.outputStream; + + self.inputStream = nil; + self.outputStream = nil; + + [inputStream removeFromRunLoop:[NSRunLoop SR_networkRunLoop] forMode:NSDefaultRunLoopMode]; + inputStream.delegate = nil; + outputStream.delegate = nil; + + _completion(nil, inputStream, outputStream); +} + +- (void)_failWithError:(NSError *)error +{ + SRDebugLog(@"_failWithError, return error"); + if (!error) { + error = SRHTTPErrorWithCodeDescription(500, 2132,@"Proxy Error"); + } + + if (_receivedHTTPHeaders) { + CFRelease(_receivedHTTPHeaders); + _receivedHTTPHeaders = NULL; + } + + self.inputStream.delegate = nil; + self.outputStream.delegate = nil; + + [self.inputStream removeFromRunLoop:[NSRunLoop SR_networkRunLoop] + forMode:NSDefaultRunLoopMode]; + [self.inputStream close]; + [self.outputStream close]; + self.inputStream = nil; + self.outputStream = nil; + _completion(error, nil, nil); +} + +// get proxy setting from device setting +- (void)_configureProxy +{ + SRDebugLog(@"configureProxy"); + NSDictionary *proxySettings = CFBridgingRelease(CFNetworkCopySystemProxySettings()); + + // CFNetworkCopyProxiesForURL doesn't understand ws:// or wss:// + NSURL *httpURL; + if (_connectionRequiresSSL) { + httpURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://%@", _url.host]]; + } else { + httpURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", _url.host]]; + } + + NSArray *proxies = CFBridgingRelease(CFNetworkCopyProxiesForURL((__bridge CFURLRef)httpURL, (__bridge CFDictionaryRef)proxySettings)); + if (proxies.count == 0) { + SRDebugLog(@"configureProxy no proxies"); + [self _openConnection]; + return; // no proxy + } + NSDictionary *settings = [proxies objectAtIndex:0]; + NSString *proxyType = settings[(NSString *)kCFProxyTypeKey]; + if ([proxyType isEqualToString:(NSString *)kCFProxyTypeAutoConfigurationURL]) { + NSURL *pacURL = settings[(NSString *)kCFProxyAutoConfigurationURLKey]; + if (pacURL) { + [self _fetchPAC:pacURL withProxySettings:proxySettings]; + return; + } + } + if ([proxyType isEqualToString:(__bridge NSString *)kCFProxyTypeAutoConfigurationJavaScript]) { + NSString *script = settings[(__bridge NSString *)kCFProxyAutoConfigurationJavaScriptKey]; + if (script) { + [self _runPACScript:script withProxySettings:proxySettings]; + return; + } + } + [self _readProxySettingWithType:proxyType settings:settings]; + + [self _openConnection]; +} + +- (void)_readProxySettingWithType:(NSString *)proxyType settings:(NSDictionary *)settings +{ + if ([proxyType isEqualToString:(NSString *)kCFProxyTypeHTTP] || + [proxyType isEqualToString:(NSString *)kCFProxyTypeHTTPS]) { + _httpProxyHost = settings[(NSString *)kCFProxyHostNameKey]; + NSNumber *portValue = settings[(NSString *)kCFProxyPortNumberKey]; + if (portValue != nil) { + _httpProxyPort = [portValue intValue]; + } + } + if ([proxyType isEqualToString:(NSString *)kCFProxyTypeSOCKS]) { + _socksProxyHost = settings[(NSString *)kCFProxyHostNameKey]; + NSNumber *portValue = settings[(NSString *)kCFProxyPortNumberKey]; + if (portValue != nil) + _socksProxyPort = [portValue intValue]; + _socksProxyUsername = settings[(NSString *)kCFProxyUsernameKey]; + _socksProxyPassword = settings[(NSString *)kCFProxyPasswordKey]; + } + if (_httpProxyHost) { + SRDebugLog(@"Using http proxy %@:%u", _httpProxyHost, _httpProxyPort); + } else if (_socksProxyHost) { + SRDebugLog(@"Using socks proxy %@:%u", _socksProxyHost, _socksProxyPort); + } else { + SRDebugLog(@"configureProxy no proxies"); + } +} + +- (void)_fetchPAC:(NSURL *)PACurl withProxySettings:(NSDictionary *)proxySettings +{ + SRDebugLog(@"SRWebSocket fetchPAC:%@", PACurl); + + if ([PACurl isFileURL]) { + NSError *error = nil; + NSString *script = [NSString stringWithContentsOfURL:PACurl + usedEncoding:NULL + error:&error]; + + if (error) { + [self _openConnection]; + } else { + [self _runPACScript:script withProxySettings:proxySettings]; + } + return; + } + + NSString *scheme = [PACurl.scheme lowercaseString]; + if (![scheme isEqualToString:@"http"] && ![scheme isEqualToString:@"https"]) { + // Don't know how to read data from this URL, we'll have to give up + // We'll simply assume no proxies, and start the request as normal + [self _openConnection]; + return; + } + __weak typeof(self) wself = self; + NSURLRequest *request = [NSURLRequest requestWithURL:PACurl]; + NSURLSession *session = [NSURLSession sharedSession]; + [[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + __strong typeof(wself) sself = wself; + if (!error) { + NSString *script = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + [sself _runPACScript:script withProxySettings:proxySettings]; + } else { + [sself _openConnection]; + } + }] resume]; +} + +- (void)_runPACScript:(NSString *)script withProxySettings:(NSDictionary *)proxySettings +{ + if (!script) { + [self _openConnection]; + return; + } + SRDebugLog(@"runPACScript"); + // From: http://developer.apple.com/samplecode/CFProxySupportTool/listing1.html + // Work around . This dummy call to + // CFNetworkCopyProxiesForURL initialise some state within CFNetwork + // that is required by CFNetworkCopyProxiesForAutoConfigurationScript. + CFBridgingRelease(CFNetworkCopyProxiesForURL((__bridge CFURLRef)_url, (__bridge CFDictionaryRef)proxySettings)); + + // Obtain the list of proxies by running the autoconfiguration script + CFErrorRef err = NULL; + + // CFNetworkCopyProxiesForAutoConfigurationScript doesn't understand ws:// or wss:// + NSURL *httpURL; + if (_connectionRequiresSSL) + httpURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://%@", _url.host]]; + else + httpURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", _url.host]]; + + NSArray *proxies = CFBridgingRelease(CFNetworkCopyProxiesForAutoConfigurationScript((__bridge CFStringRef)script,(__bridge CFURLRef)httpURL, &err)); + if (!err && [proxies count] > 0) { + NSDictionary *settings = [proxies objectAtIndex:0]; + NSString *proxyType = settings[(NSString *)kCFProxyTypeKey]; + [self _readProxySettingWithType:proxyType settings:settings]; + } + [self _openConnection]; +} + +- (void)_openConnection +{ + [self _initializeStreams]; + + [self.inputStream scheduleInRunLoop:[NSRunLoop SR_networkRunLoop] + forMode:NSDefaultRunLoopMode]; + //[self.outputStream scheduleInRunLoop:[NSRunLoop SR_networkRunLoop] + // forMode:NSDefaultRunLoopMode]; + [self.outputStream open]; + [self.inputStream open]; +} + +- (void)_initializeStreams +{ + assert(_url.port.unsignedIntValue <= UINT32_MAX); + uint32_t port = _url.port.unsignedIntValue; + if (port == 0) { + port = (_connectionRequiresSSL ? 443 : 80); + } + NSString *host = _url.host; + + if (_httpProxyHost) { + host = _httpProxyHost; + port = (_httpProxyPort ?: 80); + } + + CFReadStreamRef readStream = NULL; + CFWriteStreamRef writeStream = NULL; + + SRDebugLog(@"ProxyConnect connect stream to %@:%u", host, port); + CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)host, port, &readStream, &writeStream); + + self.outputStream = CFBridgingRelease(writeStream); + self.inputStream = CFBridgingRelease(readStream); + + if (_socksProxyHost) { + SRDebugLog(@"ProxyConnect set sock property stream to %@:%u user %@ password %@", _socksProxyHost, _socksProxyPort, _socksProxyUsername, _socksProxyPassword); + NSMutableDictionary *settings = [NSMutableDictionary dictionaryWithCapacity:4]; + settings[NSStreamSOCKSProxyHostKey] = _socksProxyHost; + if (_socksProxyPort) { + settings[NSStreamSOCKSProxyPortKey] = @(_socksProxyPort); + } + if (_socksProxyUsername) { + settings[NSStreamSOCKSProxyUserKey] = _socksProxyUsername; + } + if (_socksProxyPassword) { + settings[NSStreamSOCKSProxyPasswordKey] = _socksProxyPassword; + } + [self.inputStream setProperty:settings forKey:NSStreamSOCKSProxyConfigurationKey]; + [self.outputStream setProperty:settings forKey:NSStreamSOCKSProxyConfigurationKey]; + } + self.inputStream.delegate = self; + self.outputStream.delegate = self; +} + +- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode; +{ + SRDebugLog(@"stream handleEvent %u", eventCode); + switch (eventCode) { + case NSStreamEventOpenCompleted: { + if (aStream == self.inputStream) { + if (_httpProxyHost) { + [self _proxyDidConnect]; + } else { + [self _didConnect]; + } + } + } break; + case NSStreamEventErrorOccurred: { + [self _failWithError:aStream.streamError]; + } break; + case NSStreamEventEndEncountered: { + [self _failWithError:aStream.streamError]; + } break; + case NSStreamEventHasBytesAvailable: { + if (aStream == _inputStream) { + [self _processInputStream]; + } + } break; + case NSStreamEventHasSpaceAvailable: + case NSStreamEventNone: + SRDebugLog(@"(default) %@", aStream); + break; + } +} + +- (void)_proxyDidConnect +{ + SRDebugLog(@"Proxy Connected"); + uint32_t port = _url.port.unsignedIntValue; + if (port == 0) { + port = (_connectionRequiresSSL ? 443 : 80); + } + // Send HTTP CONNECT Request + NSString *connectRequestStr = [NSString stringWithFormat:@"CONNECT %@:%u HTTP/1.1\r\nHost: %@\r\nConnection: keep-alive\r\nProxy-Connection: keep-alive\r\n\r\n", _url.host, port, _url.host]; + + NSData *message = [connectRequestStr dataUsingEncoding:NSUTF8StringEncoding]; + SRDebugLog(@"Proxy sending %@", connectRequestStr); + + [self _writeData:message]; +} + +///handles the incoming bytes and sending them to the proper processing method +- (void)_processInputStream +{ + NSMutableData *buf = [NSMutableData dataWithCapacity:SRDefaultBufferSize()]; + uint8_t *buffer = buf.mutableBytes; + NSInteger length = [_inputStream read:buffer maxLength:SRDefaultBufferSize()]; + + if (length <= 0) { + return; + } + + BOOL process = (_inputQueue.count == 0); + [_inputQueue addObject:[NSData dataWithBytes:buffer length:length]]; + + if (process) { + [self _dequeueInput]; + } +} + +// dequeue the incoming input so it is processed in order + +- (void)_dequeueInput +{ + while (_inputQueue.count > 0) { + NSData *data = _inputQueue.firstObject; + [_inputQueue removeObjectAtIndex:0]; + + // No need to process any data further, we got the full header data. + if ([self _proxyProcessHTTPResponseWithData:data]) { + break; + } + } +} +//handle checking the proxy connection status +- (BOOL)_proxyProcessHTTPResponseWithData:(NSData *)data +{ + if (_receivedHTTPHeaders == NULL) { + _receivedHTTPHeaders = CFHTTPMessageCreateEmpty(NULL, NO); + } + + CFHTTPMessageAppendBytes(_receivedHTTPHeaders, (const UInt8 *)data.bytes, data.length); + if (CFHTTPMessageIsHeaderComplete(_receivedHTTPHeaders)) { + SRDebugLog(@"Finished reading headers %@", CFBridgingRelease(CFHTTPMessageCopyAllHeaderFields(_receivedHTTPHeaders))); + [self _proxyHTTPHeadersDidFinish]; + return YES; + } + + return NO; +} + +- (void)_proxyHTTPHeadersDidFinish +{ + NSInteger responseCode = CFHTTPMessageGetResponseStatusCode(_receivedHTTPHeaders); + + if (responseCode >= 299) { + SRDebugLog(@"Connect to Proxy Request failed with response code %d", responseCode); + NSError *error = SRHTTPErrorWithCodeDescription(responseCode, 2132, + [NSString stringWithFormat:@"Received bad response code from proxy server: %d.", + (int)responseCode]); + [self _failWithError:error]; + return; + } + SRDebugLog(@"proxy connect return %d, call socket connect", responseCode); + [self _didConnect]; +} + +static NSTimeInterval const SRProxyConnectWriteTimeout = 5.0; + +- (void)_writeData:(NSData *)data +{ + const uint8_t * bytes = data.bytes; + __block NSInteger timeout = (NSInteger)(SRProxyConnectWriteTimeout * 1000000); // wait timeout before giving up + __weak typeof(self) wself = self; + dispatch_async(_writeQueue, ^{ + __strong typeof(wself) sself = self; + if (!sself) { + return; + } + NSOutputStream *outStream = sself.outputStream; + if (!outStream) { + return; + } + while (![outStream hasSpaceAvailable]) { + usleep(100); //wait until the socket is ready + timeout -= 100; + if (timeout < 0) { + NSError *error = SRHTTPErrorWithCodeDescription(408, 2132, @"Proxy timeout"); + [sself _failWithError:error]; + } else if (outStream.streamError != nil) { + [sself _failWithError:outStream.streamError]; + } + } + [outStream write:bytes maxLength:data.length]; + }); +} + +@end diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/RunLoop/SRRunLoopThread.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/RunLoop/SRRunLoopThread.h new file mode 100755 index 0000000..380cfa0 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/RunLoop/SRRunLoopThread.h @@ -0,0 +1,24 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface SRRunLoopThread : NSThread + +@property (nonatomic, strong, readonly) NSRunLoop *runLoop; + ++ (instancetype)sharedThread; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/RunLoop/SRRunLoopThread.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/RunLoop/SRRunLoopThread.m new file mode 100755 index 0000000..a02b1e0 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/RunLoop/SRRunLoopThread.m @@ -0,0 +1,83 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRRunLoopThread.h" + +@interface SRRunLoopThread () +{ + dispatch_group_t _waitGroup; +} + +@property (nonatomic, strong, readwrite) NSRunLoop *runLoop; + +@end + +@implementation SRRunLoopThread + ++ (instancetype)sharedThread +{ + static SRRunLoopThread *thread; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + thread = [[SRRunLoopThread alloc] init]; + thread.name = @"com.facebook.SocketRocket.NetworkThread"; + [thread start]; + }); + return thread; +} + +- (instancetype)init +{ + self = [super init]; + if (self) { + _waitGroup = dispatch_group_create(); + dispatch_group_enter(_waitGroup); + } + return self; +} + +- (void)main +{ + @autoreleasepool { + _runLoop = [NSRunLoop currentRunLoop]; + dispatch_group_leave(_waitGroup); + + // Add an empty run loop source to prevent runloop from spinning. + CFRunLoopSourceContext sourceCtx = { + .version = 0, + .info = NULL, + .retain = NULL, + .release = NULL, + .copyDescription = NULL, + .equal = NULL, + .hash = NULL, + .schedule = NULL, + .cancel = NULL, + .perform = NULL + }; + CFRunLoopSourceRef source = CFRunLoopSourceCreate(NULL, 0, &sourceCtx); + CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode); + CFRelease(source); + + while ([_runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) { + + } + assert(NO); + } +} + +- (NSRunLoop *)runLoop; +{ + dispatch_group_wait(_waitGroup, DISPATCH_TIME_FOREVER); + return _runLoop; +} + +@end diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/SRConstants.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/SRConstants.h new file mode 100755 index 0000000..2244213 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/SRConstants.h @@ -0,0 +1,26 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +typedef NS_ENUM(NSInteger, SROpCode) +{ + SROpCodeTextFrame = 0x1, + SROpCodeBinaryFrame = 0x2, + // 3-7 reserved. + SROpCodeConnectionClose = 0x8, + SROpCodePing = 0x9, + SROpCodePong = 0xA, + // B-F reserved. +}; + +/** + Default buffer size that is used for reading/writing to streams. + */ +extern size_t SRDefaultBufferSize(void); diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/SRConstants.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/SRConstants.m new file mode 100755 index 0000000..deb6165 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/SRConstants.m @@ -0,0 +1,19 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRConstants.h" + +size_t SRDefaultBufferSize(void) { + static size_t size; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + size = getpagesize(); + }); + return size; +} diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Security/SRPinningSecurityPolicy.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Security/SRPinningSecurityPolicy.h new file mode 100755 index 0000000..0d498b2 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Security/SRPinningSecurityPolicy.h @@ -0,0 +1,27 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + * NOTE: While publicly, SocketRocket does not support configuring the security policy with pinned certificates, + * it is still possible to manually construct a security policy of this class. If you do this, note that you may + * be open to MitM attacks, and we will not support any issues you may have. Dive at your own risk. + */ +@interface SRPinningSecurityPolicy : SRSecurityPolicy + +- (instancetype)initWithCertificates:(NSArray *)pinnedCertificates; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Security/SRPinningSecurityPolicy.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Security/SRPinningSecurityPolicy.m new file mode 100755 index 0000000..a906e2a --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Security/SRPinningSecurityPolicy.m @@ -0,0 +1,73 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRPinningSecurityPolicy.h" + +#import + +#import "SRLog.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SRPinningSecurityPolicy () + +@property (nonatomic, copy, readonly) NSArray *pinnedCertificates; + +@end + +@implementation SRPinningSecurityPolicy + +- (instancetype)initWithCertificates:(NSArray *)pinnedCertificates +{ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated" + + // Do not validate certificate chain since we're pinning to specific certificates. + self = [super initWithCertificateChainValidationEnabled:NO]; + +#pragma clang diagnostic pop + + if (!self) { return self; } + + if (pinnedCertificates.count == 0) { + @throw [NSException exceptionWithName:@"Creating security policy failed." + reason:@"Must specify at least one certificate when creating a pinning policy." + userInfo:nil]; + } + _pinnedCertificates = [pinnedCertificates copy]; + + return self; +} + +- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain +{ + SRDebugLog(@"Pinned cert count: %d", self.pinnedCertificates.count); + NSUInteger requiredCertCount = self.pinnedCertificates.count; + + NSUInteger validatedCertCount = 0; + CFIndex serverCertCount = SecTrustGetCertificateCount(serverTrust); + for (CFIndex i = 0; i < serverCertCount; i++) { + SecCertificateRef cert = SecTrustGetCertificateAtIndex(serverTrust, i); + NSData *data = CFBridgingRelease(SecCertificateCopyData(cert)); + for (id ref in self.pinnedCertificates) { + SecCertificateRef trustedCert = (__bridge SecCertificateRef)ref; + // TODO: (nlutsenko) Add caching, so we don't copy the data for every pinned cert all the time. + NSData *trustedCertData = CFBridgingRelease(SecCertificateCopyData(trustedCert)); + if ([trustedCertData isEqualToData:data]) { + validatedCertCount++; + break; + } + } + } + return (requiredCertCount == validatedCertCount); +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRError.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRError.h new file mode 100755 index 0000000..7e13a82 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRError.h @@ -0,0 +1,20 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +extern NSError *SRErrorWithDomainCodeDescription(NSString *domain, NSInteger code, NSString *description); +extern NSError *SRErrorWithCodeDescription(NSInteger code, NSString *description); +extern NSError *SRErrorWithCodeDescriptionUnderlyingError(NSInteger code, NSString *description, NSError *underlyingError); + +extern NSError *SRHTTPErrorWithCodeDescription(NSInteger httpCode, NSInteger errorCode, NSString *description); + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRError.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRError.m new file mode 100755 index 0000000..71ae729 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRError.m @@ -0,0 +1,42 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRError.h" + +#import "SRWebSocket.h" + +NS_ASSUME_NONNULL_BEGIN + +NSError *SRErrorWithDomainCodeDescription(NSString *domain, NSInteger code, NSString *description) +{ + return [NSError errorWithDomain:domain code:code userInfo:@{ NSLocalizedDescriptionKey: description }]; +} + +NSError *SRErrorWithCodeDescription(NSInteger code, NSString *description) +{ + return SRErrorWithDomainCodeDescription(SRWebSocketErrorDomain, code, description); +} + +NSError *SRErrorWithCodeDescriptionUnderlyingError(NSInteger code, NSString *description, NSError *underlyingError) +{ + return [NSError errorWithDomain:SRWebSocketErrorDomain + code:code + userInfo:@{ NSLocalizedDescriptionKey: description, + NSUnderlyingErrorKey: underlyingError }]; +} + +NSError *SRHTTPErrorWithCodeDescription(NSInteger httpCode, NSInteger errorCode, NSString *description) +{ + return [NSError errorWithDomain:SRWebSocketErrorDomain + code:errorCode + userInfo:@{ NSLocalizedDescriptionKey: description, + SRHTTPResponseErrorKey: @(httpCode) }]; +} + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHTTPConnectMessage.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHTTPConnectMessage.h new file mode 100755 index 0000000..1e2302a --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHTTPConnectMessage.h @@ -0,0 +1,20 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +extern CFHTTPMessageRef SRHTTPConnectMessageCreate(NSURLRequest *request, + NSString *securityKey, + uint8_t webSocketProtocolVersion, + NSArray *_Nullable cookies, + NSArray *_Nullable requestedProtocols); + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHTTPConnectMessage.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHTTPConnectMessage.m new file mode 100755 index 0000000..71caa00 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHTTPConnectMessage.m @@ -0,0 +1,79 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRHTTPConnectMessage.h" + +#import "SRURLUtilities.h" + +NS_ASSUME_NONNULL_BEGIN + +static NSString *_SRHTTPConnectMessageHost(NSURL *url) +{ + NSString *host = url.host; + if (url.port != nil) { + host = [host stringByAppendingFormat:@":%@", url.port]; + } + return host; +} + +CFHTTPMessageRef SRHTTPConnectMessageCreate(NSURLRequest *request, + NSString *securityKey, + uint8_t webSocketProtocolVersion, + NSArray *_Nullable cookies, + NSArray *_Nullable requestedProtocols) +{ + NSURL *url = request.URL; + + CFHTTPMessageRef message = CFHTTPMessageCreateRequest(NULL, CFSTR("GET"), (__bridge CFURLRef)url, kCFHTTPVersion1_1); + + // Set host first so it defaults + CFHTTPMessageSetHeaderFieldValue(message, CFSTR("Host"), (__bridge CFStringRef)_SRHTTPConnectMessageHost(url)); + + NSMutableData *keyBytes = [[NSMutableData alloc] initWithLength:16]; + int result = SecRandomCopyBytes(kSecRandomDefault, keyBytes.length, keyBytes.mutableBytes); + if (result != 0) { + //TODO: (nlutsenko) Check if there was an error. + } + + // Apply cookies if any have been provided + if (cookies) { + NSDictionary *messageCookies = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies]; + [messageCookies enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString * _Nonnull obj, BOOL * _Nonnull stop) { + if (key.length && obj.length) { + CFHTTPMessageSetHeaderFieldValue(message, (__bridge CFStringRef)key, (__bridge CFStringRef)obj); + } + }]; + } + + // set header for http basic auth + NSString *basicAuthorizationString = SRBasicAuthorizationHeaderFromURL(url); + if (basicAuthorizationString) { + CFHTTPMessageSetHeaderFieldValue(message, CFSTR("Authorization"), (__bridge CFStringRef)basicAuthorizationString); + } + + CFHTTPMessageSetHeaderFieldValue(message, CFSTR("Upgrade"), CFSTR("websocket")); + CFHTTPMessageSetHeaderFieldValue(message, CFSTR("Connection"), CFSTR("Upgrade")); + CFHTTPMessageSetHeaderFieldValue(message, CFSTR("Sec-WebSocket-Key"), (__bridge CFStringRef)securityKey); + CFHTTPMessageSetHeaderFieldValue(message, CFSTR("Sec-WebSocket-Version"), (__bridge CFStringRef)@(webSocketProtocolVersion).stringValue); + + CFHTTPMessageSetHeaderFieldValue(message, CFSTR("Origin"), (__bridge CFStringRef)SRURLOrigin(url)); + + if (requestedProtocols.count) { + CFHTTPMessageSetHeaderFieldValue(message, CFSTR("Sec-WebSocket-Protocol"), + (__bridge CFStringRef)[requestedProtocols componentsJoinedByString:@", "]); + } + + [request.allHTTPHeaderFields enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { + CFHTTPMessageSetHeaderFieldValue(message, (__bridge CFStringRef)key, (__bridge CFStringRef)obj); + }]; + + return message; +} + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHash.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHash.h new file mode 100755 index 0000000..3db14de --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHash.h @@ -0,0 +1,19 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +extern NSData *SRSHA1HashFromString(NSString *string); +extern NSData *SRSHA1HashFromBytes(const char *bytes, size_t length); + +extern NSString *SRBase64EncodedStringFromData(NSData *data); + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHash.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHash.m new file mode 100755 index 0000000..275ae90 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRHash.m @@ -0,0 +1,43 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRHash.h" + +#import + +NS_ASSUME_NONNULL_BEGIN + +NSData *SRSHA1HashFromString(NSString *string) +{ + size_t length = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + return SRSHA1HashFromBytes(string.UTF8String, length); +} + +NSData *SRSHA1HashFromBytes(const char *bytes, size_t length) +{ + uint8_t outputLength = CC_SHA1_DIGEST_LENGTH; + unsigned char output[outputLength]; + CC_SHA1(bytes, (CC_LONG)length, output); + + return [NSData dataWithBytes:output length:outputLength]; +} + +NSString *SRBase64EncodedStringFromData(NSData *data) +{ + if ([data respondsToSelector:@selector(base64EncodedStringWithOptions:)]) { + return [data base64EncodedStringWithOptions:0]; + } + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + return [data base64Encoding]; +#pragma clang diagnostic pop +} + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRLog.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRLog.h new file mode 100755 index 0000000..99689ef --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRLog.h @@ -0,0 +1,20 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +// Uncomment this line to enable debug logging +//#define SR_DEBUG_LOG_ENABLED + +extern void SRErrorLog(NSString *format, ...); +extern void SRDebugLog(NSString *format, ...); + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRLog.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRLog.m new file mode 100755 index 0000000..1c66475 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRLog.m @@ -0,0 +1,33 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRLog.h" + +NS_ASSUME_NONNULL_BEGIN + +extern void SRErrorLog(NSString *format, ...) +{ + __block va_list arg_list; + va_start (arg_list, format); + + NSString *formattedString = [[NSString alloc] initWithFormat:format arguments:arg_list]; + + va_end(arg_list); + + NSLog(@"[SocketRocket] %@", formattedString); +} + +extern void SRDebugLog(NSString *format, ...) +{ +#ifdef SR_DEBUG_LOG_ENABLED + SRErrorLog(tag, format); +#endif +} + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRMutex.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRMutex.h new file mode 100755 index 0000000..8226ce6 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRMutex.h @@ -0,0 +1,22 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +typedef __attribute__((capability("mutex"))) pthread_mutex_t *SRMutex; + +extern SRMutex SRMutexInitRecursive(void); +extern void SRMutexDestroy(SRMutex mutex); + +extern void SRMutexLock(SRMutex mutex) __attribute__((acquire_capability(mutex))); +extern void SRMutexUnlock(SRMutex mutex) __attribute__((release_capability(mutex))); + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRMutex.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRMutex.m new file mode 100755 index 0000000..a8b978c --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRMutex.m @@ -0,0 +1,47 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRMutex.h" + +#import + +NS_ASSUME_NONNULL_BEGIN + +SRMutex SRMutexInitRecursive(void) +{ + pthread_mutex_t *mutex = malloc(sizeof(pthread_mutex_t)); + pthread_mutexattr_t attributes; + + pthread_mutexattr_init(&attributes); + pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(mutex, &attributes); + pthread_mutexattr_destroy(&attributes); + + return mutex; +} + +void SRMutexDestroy(SRMutex mutex) +{ + pthread_mutex_destroy(mutex); + free(mutex); +} + +__attribute__((no_thread_safety_analysis)) +void SRMutexLock(SRMutex mutex) +{ + pthread_mutex_lock(mutex); +} + +__attribute__((no_thread_safety_analysis)) +void SRMutexUnlock(SRMutex mutex) +{ + pthread_mutex_unlock(mutex); +} + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRRandom.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRRandom.h new file mode 100755 index 0000000..9b116cf --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRRandom.h @@ -0,0 +1,16 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +extern NSData *SRRandomData(NSUInteger length); + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRRandom.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRRandom.m new file mode 100755 index 0000000..37911bb --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRRandom.m @@ -0,0 +1,26 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRRandom.h" + +#import + +NS_ASSUME_NONNULL_BEGIN + +NSData *SRRandomData(NSUInteger length) +{ + NSMutableData *data = [NSMutableData dataWithLength:length]; + int result = SecRandomCopyBytes(kSecRandomDefault, data.length, data.mutableBytes); + if (result != 0) { + [NSException raise:NSInternalInconsistencyException format:@"Failed to generate random bytes with OSStatus: %d", result]; + } + return data; +} + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRSIMDHelpers.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRSIMDHelpers.h new file mode 100755 index 0000000..8291cc7 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRSIMDHelpers.h @@ -0,0 +1,19 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +/** + Unmask bytes using XOR via SIMD. + + @param bytes The bytes to unmask. + @param length The number of bytes to unmask. + @param maskKey The mask to XOR with MUST be of length sizeof(uint32_t). + */ +void SRMaskBytesSIMD(uint8_t *bytes, size_t length, uint8_t *maskKey); diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRSIMDHelpers.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRSIMDHelpers.m new file mode 100755 index 0000000..aa59535 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRSIMDHelpers.m @@ -0,0 +1,73 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRSIMDHelpers.h" + +typedef uint8_t uint8x32_t __attribute__((vector_size(32))); + +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)]; + } +} + +/** + Right-shift the elements of a vector, circularly. + + @param vector The vector to circular shift. + @param by The number of elements to shift by. + + @return A shifted vector. + */ +static uint8x32_t SRShiftVector(uint8x32_t vector, size_t by) { + uint8x32_t vectorCopy = vector; + by = by % _Alignof(uint8x32_t); + + uint8_t *vectorPointer = (uint8_t *)&vector; + uint8_t *vectorCopyPointer = (uint8_t *)&vectorCopy; + + memmove(vectorPointer + by, vectorPointer, sizeof(vector) - by); + memcpy(vectorPointer, vectorCopyPointer + (sizeof(vector) - by), by); + + return vector; +} + +void SRMaskBytesSIMD(uint8_t *bytes, size_t length, uint8_t *maskKey) { + size_t alignmentBytes = _Alignof(uint8x32_t) - ((uintptr_t)bytes % _Alignof(uint8x32_t)); + if (alignmentBytes == _Alignof(uint8x32_t)) { + alignmentBytes = 0; + } + + // If the number of bytes that can be processed after aligning is + // less than the number of bytes we can put into a vector, + // then there's no work to do with SIMD, just call the manual version. + if (alignmentBytes > length || (length - alignmentBytes) < sizeof(uint8x32_t)) { + SRMaskBytesManual(bytes, length, maskKey); + return; + } + + size_t vectorLength = (length - alignmentBytes) / sizeof(uint8x32_t); + size_t manualStartOffset = alignmentBytes + (vectorLength * sizeof(uint8x32_t)); + size_t manualLength = length - manualStartOffset; + + uint8x32_t *vector = (uint8x32_t *)(bytes + alignmentBytes); + uint8x32_t maskVector = { }; + + memset_pattern4(&maskVector, maskKey, sizeof(uint8x32_t)); + maskVector = SRShiftVector(maskVector, alignmentBytes); + + SRMaskBytesManual(bytes, alignmentBytes, maskKey); + + for (size_t vectorIndex = 0; vectorIndex < vectorLength; vectorIndex++) { + vector[vectorIndex] = vector[vectorIndex] ^ maskVector; + } + + // Use the shifted mask for the final manual part. + SRMaskBytesManual(bytes + manualStartOffset, manualLength, (uint8_t *) &maskVector); +} diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRURLUtilities.h b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRURLUtilities.h new file mode 100755 index 0000000..a445380 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRURLUtilities.h @@ -0,0 +1,26 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +// The origin isn't really applicable for a native application. +// So instead, just map ws -> http and wss -> https. +extern NSString *SRURLOrigin(NSURL *url); + +extern BOOL SRURLRequiresSSL(NSURL *url); + +// Extracts `user` and `password` from url (if available) into `Basic base64(user:password)`. +extern NSString *_Nullable SRBasicAuthorizationHeaderFromURL(NSURL *url); + +// Returns a valid value for `NSStreamNetworkServiceType` or `nil`. +extern NSString *_Nullable SRStreamNetworkServiceTypeFromURLRequest(NSURLRequest *request); + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRURLUtilities.m b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRURLUtilities.m new file mode 100755 index 0000000..45d618b --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Internal/Utilities/SRURLUtilities.m @@ -0,0 +1,72 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRURLUtilities.h" + +#import "SRHash.h" + +NS_ASSUME_NONNULL_BEGIN + +NSString *SRURLOrigin(NSURL *url) +{ + NSMutableString *origin = [NSMutableString string]; + + NSString *scheme = url.scheme.lowercaseString; + if ([scheme isEqualToString:@"wss"]) { + scheme = @"https"; + } else if ([scheme isEqualToString:@"ws"]) { + scheme = @"http"; + } + [origin appendFormat:@"%@://%@", scheme, url.host]; + + NSNumber *port = url.port; + BOOL portIsDefault = ((port == nil) || + ([scheme isEqualToString:@"http"] && port.integerValue == 80) || + ([scheme isEqualToString:@"https"] && port.integerValue == 443)); + if (!portIsDefault) { + [origin appendFormat:@":%@", port.stringValue]; + } + return origin; +} + +extern BOOL SRURLRequiresSSL(NSURL *url) +{ + NSString *scheme = url.scheme.lowercaseString; + return ([scheme isEqualToString:@"wss"] || [scheme isEqualToString:@"https"]); +} + +extern NSString *_Nullable SRBasicAuthorizationHeaderFromURL(NSURL *url) +{ + NSData *data = [[NSString stringWithFormat:@"%@:%@", url.user, url.password] dataUsingEncoding:NSUTF8StringEncoding]; + return [NSString stringWithFormat:@"Basic %@", SRBase64EncodedStringFromData(data)]; +} + +extern NSString *_Nullable SRStreamNetworkServiceTypeFromURLRequest(NSURLRequest *request) +{ + NSString *networkServiceType = nil; + switch (request.networkServiceType) { + case NSURLNetworkServiceTypeDefault: + break; + case NSURLNetworkServiceTypeVoIP: + networkServiceType = NSStreamNetworkServiceTypeVoIP; + break; + case NSURLNetworkServiceTypeVideo: + networkServiceType = NSStreamNetworkServiceTypeVideo; + break; + case NSURLNetworkServiceTypeBackground: + networkServiceType = NSStreamNetworkServiceTypeBackground; + break; + case NSURLNetworkServiceTypeVoice: + networkServiceType = NSStreamNetworkServiceTypeVoice; + break; + } + return networkServiceType; +} + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/NSRunLoop+SRWebSocket.h b/Sources/Vendor/SocketRocket/SocketRocket/NSRunLoop+SRWebSocket.h new file mode 100755 index 0000000..8f419e3 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/NSRunLoop+SRWebSocket.h @@ -0,0 +1,27 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NSRunLoop (SRWebSocket) + +/** + Default run loop that will be used to schedule all instances of `SRWebSocket`. + + @return An instance of `NSRunLoop`. + */ ++ (NSRunLoop *)SR_networkRunLoop; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/NSRunLoop+SRWebSocket.m b/Sources/Vendor/SocketRocket/SocketRocket/NSRunLoop+SRWebSocket.m new file mode 100755 index 0000000..f926f90 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/NSRunLoop+SRWebSocket.m @@ -0,0 +1,27 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "NSRunLoop+SRWebSocket.h" +#import "NSRunLoop+SRWebSocketPrivate.h" + +#import "SRRunLoopThread.h" + +// Required for object file to always be linked. +void import_NSRunLoop_SRWebSocket() { } + +@implementation NSRunLoop (SRWebSocket) + ++ (NSRunLoop *)SR_networkRunLoop +{ + return [SRRunLoopThread sharedThread].runLoop; +} + +@end diff --git a/Sources/Vendor/SocketRocket/SocketRocket/NSURLRequest+SRWebSocket.h b/Sources/Vendor/SocketRocket/SocketRocket/NSURLRequest+SRWebSocket.h new file mode 100755 index 0000000..1ddf93f --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/NSURLRequest+SRWebSocket.h @@ -0,0 +1,38 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NSURLRequest (SRWebSocket) + +/** + An array of pinned `SecCertificateRef` SSL certificates that `SRWebSocket` will use for validation. + */ +@property (nullable, nonatomic, copy, readonly) NSArray *SR_SSLPinnedCertificates + DEPRECATED_MSG_ATTRIBUTE("Using pinned certificates is neither secure nor supported in SocketRocket, " + "and leads to security issues. Please use a proper, trust chain validated certificate."); + +@end + +@interface NSMutableURLRequest (SRWebSocket) + +/** + An array of pinned `SecCertificateRef` SSL certificates that `SRWebSocket` will use for validation. + */ +@property (nullable, nonatomic, copy) NSArray *SR_SSLPinnedCertificates + DEPRECATED_MSG_ATTRIBUTE("Using pinned certificates is neither secure nor supported in SocketRocket, " + "and leads to security issues. Please use a proper, trust chain validated certificate."); + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/NSURLRequest+SRWebSocket.m b/Sources/Vendor/SocketRocket/SocketRocket/NSURLRequest+SRWebSocket.m new file mode 100755 index 0000000..d1a8999 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/NSURLRequest+SRWebSocket.m @@ -0,0 +1,42 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "NSURLRequest+SRWebSocket.h" +#import "NSURLRequest+SRWebSocketPrivate.h" + +// Required for object file to always be linked. +void import_NSURLRequest_SRWebSocket() { } + +NS_ASSUME_NONNULL_BEGIN + +static NSString *const SRSSLPinnnedCertificatesKey = @"SocketRocket_SSLPinnedCertificates"; + +@implementation NSURLRequest (SRWebSocket) + +- (nullable NSArray *)SR_SSLPinnedCertificates +{ + return nil; +} + +@end + +@implementation NSMutableURLRequest (SRWebSocket) + +- (void)setSR_SSLPinnedCertificates:(nullable NSArray *)SR_SSLPinnedCertificates +{ + [NSException raise:NSInvalidArgumentException + format:@"Using pinned certificates is neither secure nor supported in SocketRocket, " + "and leads to security issues. Please use a proper, trust chain validated certificate."]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/Resources/Info.plist b/Sources/Vendor/SocketRocket/SocketRocket/Resources/Info.plist new file mode 100755 index 0000000..d3de8ee --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/Resources/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/Sources/Vendor/SocketRocket/SocketRocket/SRSecurityPolicy.h b/Sources/Vendor/SocketRocket/SocketRocket/SRSecurityPolicy.h new file mode 100755 index 0000000..db6286d --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/SRSecurityPolicy.h @@ -0,0 +1,72 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface SRSecurityPolicy : NSObject + +/** + A default `SRSecurityPolicy` implementation specifies socket security and + validates the certificate chain. + + Use a subclass of `SRSecurityPolicy` for more fine grained customization. + */ ++ (instancetype)defaultPolicy; + +/** + Specifies socket security and provider certificate pinning, disregarding certificate + chain validation. + + @param pinnedCertificates Array of `SecCertificateRef` SSL certificates to use for validation. + */ ++ (instancetype)pinnningPolicyWithCertificates:(NSArray *)pinnedCertificates + DEPRECATED_MSG_ATTRIBUTE("Using pinned certificates is neither secure nor supported in SocketRocket, " + "and leads to security issues. Please use a proper, trust chain validated certificate."); + +/** + Specifies socket security and optional certificate chain validation. + + @param enabled Whether or not to validate the SSL certificate chain. If you + are considering using this method because your certificate was not issued by a + recognized certificate authority, consider using `pinningPolicyWithCertificates` instead. + */ +- (instancetype)initWithCertificateChainValidationEnabled:(BOOL)enabled + DEPRECATED_MSG_ATTRIBUTE("Disabling certificate chain validation is unsafe. " + "Please use a proper Certificate Authority to issue your TLS certificates.") + NS_DESIGNATED_INITIALIZER; + +/** + Updates all the security options for input and output streams, for example you + can set your socket security level here. + + @param stream Stream to update the options in. + */ +- (void)updateSecurityOptionsInStream:(NSStream *)stream; + +/** + Whether or not the specified server trust should be accepted, based on the security policy. + + This method should be used when responding to an authentication challenge from + a server. In the default implemenation, no further validation is done here, but + you're free to override it in a subclass. See `SRPinningSecurityPolicy.h` for + an example. + + @param serverTrust The X.509 certificate trust of the server. + @param domain The domain of serverTrust. + + @return Whether or not to trust the server. + */ +- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/SRSecurityPolicy.m b/Sources/Vendor/SocketRocket/SocketRocket/SRSecurityPolicy.m new file mode 100755 index 0000000..96e11e9 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/SRSecurityPolicy.m @@ -0,0 +1,75 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRSecurityPolicy.h" +#import "SRPinningSecurityPolicy.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SRSecurityPolicy () + +@property (nonatomic, assign, readonly) BOOL certificateChainValidationEnabled; + +@end + +@implementation SRSecurityPolicy + ++ (instancetype)defaultPolicy +{ + return [self new]; +} + ++ (instancetype)pinnningPolicyWithCertificates:(NSArray *)pinnedCertificates +{ + [NSException raise:NSInvalidArgumentException + format:@"Using pinned certificates is neither secure nor supported in SocketRocket, " + "and leads to security issues. Please use a proper, trust chain validated certificate."]; + + return nil; +} + +- (instancetype)initWithCertificateChainValidationEnabled:(BOOL)enabled +{ + self = [super init]; + if (!self) { return self; } + + _certificateChainValidationEnabled = enabled; + + return self; +} + +- (instancetype)init +{ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated" + + return [self initWithCertificateChainValidationEnabled:YES]; + +#pragma clang diagnostic pop +} + +- (void)updateSecurityOptionsInStream:(NSStream *)stream +{ + // Enforce TLS 1.2 + [stream setProperty:(__bridge id)CFSTR("kCFStreamSocketSecurityLevelTLSv1_2") forKey:(__bridge id)kCFStreamPropertySocketSecurityLevel]; + + // Validate certificate chain for this stream if enabled. + NSDictionary *sslOptions = @{ (__bridge NSString *)kCFStreamSSLValidatesCertificateChain : @(self.certificateChainValidationEnabled) }; + [stream setProperty:sslOptions forKey:(__bridge NSString *)kCFStreamPropertySSLSettings]; +} + +- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain +{ + // No further evaluation happens in the default policy. + return YES; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/SRWebSocket.h b/Sources/Vendor/SocketRocket/SocketRocket/SRWebSocket.h new file mode 100755 index 0000000..df483c0 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/SRWebSocket.h @@ -0,0 +1,417 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSInteger, SRReadyState) { + SR_CONNECTING = 0, + SR_OPEN = 1, + SR_CLOSING = 2, + SR_CLOSED = 3, +}; + +typedef NS_ENUM(NSInteger, SRStatusCode) { + // 0-999: Reserved and not used. + SRStatusCodeNormal = 1000, + SRStatusCodeGoingAway = 1001, + SRStatusCodeProtocolError = 1002, + SRStatusCodeUnhandledType = 1003, + // 1004 reserved. + SRStatusNoStatusReceived = 1005, + SRStatusCodeAbnormal = 1006, + SRStatusCodeInvalidUTF8 = 1007, + SRStatusCodePolicyViolated = 1008, + SRStatusCodeMessageTooBig = 1009, + SRStatusCodeMissingExtension = 1010, + SRStatusCodeInternalError = 1011, + SRStatusCodeServiceRestart = 1012, + SRStatusCodeTryAgainLater = 1013, + // 1014: Reserved for future use by the WebSocket standard. + SRStatusCodeTLSHandshake = 1015, + // 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; +@class SRSecurityPolicy; + +/** + Error domain used for errors reported by SRWebSocket. + */ +extern NSString *const SRWebSocketErrorDomain; + +/** + Key used for HTTP status code if bad response was received from the server. + */ +extern NSString *const SRHTTPResponseErrorKey; + +@protocol SRWebSocketDelegate; + +///-------------------------------------- +#pragma mark - SRWebSocket +///-------------------------------------- + +/** + A `SRWebSocket` object lets you connect, send and receive data to a remote Web Socket. + */ +@interface SRWebSocket : NSObject + +/** + The delegate of the web socket. + + The web socket delegate is notified on all state changes that happen to the web socket. + */ +@property (nonatomic, weak) id delegate; + +/** + A dispatch queue for scheduling the delegate calls. The queue doesn't need be a serial queue. + + If `nil` and `delegateOperationQueue` is `nil`, the socket uses main queue for performing all delegate method calls. + */ +@property (nullable, nonatomic, strong) dispatch_queue_t delegateDispatchQueue; + +/** + An operation queue for scheduling the delegate calls. + + If `nil` and `delegateOperationQueue` is `nil`, the socket uses main queue for performing all delegate method calls. + */ +@property (nullable, nonatomic, strong) NSOperationQueue *delegateOperationQueue; + +/** + Current ready state of the socket. Default: `SR_CONNECTING`. + + This property is Key-Value Observable and fully thread-safe. + */ +@property (atomic, assign, readonly) SRReadyState readyState; + +/** + An instance of `NSURL` that this socket connects to. + */ +@property (nullable, nonatomic, strong, readonly) NSURL *url; + +/** + All HTTP headers that were received by socket or `nil` if none were received so far. + */ +@property (nullable, nonatomic, assign, readonly) CFHTTPMessageRef receivedHTTPHeaders; + +/** + Array of `NSHTTPCookie` cookies to apply to the connection. + */ +@property (nullable, nonatomic, copy) NSArray *requestCookies; + +/** + The negotiated web socket protocol or `nil` if handshake did not yet complete. + */ +@property (nullable, nonatomic, copy, readonly) NSString *protocol; + +/** + A boolean value indicating whether this socket will allow connection without SSL trust chain evaluation. + For DEBUG builds this flag is ignored, and SSL connections are allowed regardless of the certificate trust configuration + */ +@property (nonatomic, assign, readonly) BOOL allowsUntrustedSSLCertificates; + +///-------------------------------------- +#pragma mark - Constructors +///-------------------------------------- + +/** + Initializes a web socket with a given `NSURLRequest`. + + @param request Request to initialize with. + */ +- (instancetype)initWithURLRequest:(NSURLRequest *)request; + +/** + Initializes a web socket with a given `NSURLRequest`, specifying a transport security policy (e.g. SSL configuration). + + @param request Request to initialize with. + @param securityPolicy Policy object describing transport security behavior. + */ +- (instancetype)initWithURLRequest:(NSURLRequest *)request securityPolicy:(SRSecurityPolicy *)securityPolicy; + +/** + Initializes a web socket with a given `NSURLRequest` and list of sub-protocols. + + @param request Request to initialize with. + @param protocols An array of strings that turn into `Sec-WebSocket-Protocol`. Default: `nil`. + */ +- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(nullable NSArray *)protocols; + +/** + Initializes a web socket with a given `NSURLRequest`, list of sub-protocols and whether untrusted SSL certificates are allowed. + + @param request Request to initialize with. + @param protocols An array of strings that turn into `Sec-WebSocket-Protocol`. Default: `nil`. + @param allowsUntrustedSSLCertificates Boolean value indicating whether untrusted SSL certificates are allowed. Default: `false`. + */ +- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(nullable NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates + DEPRECATED_MSG_ATTRIBUTE("Disabling certificate chain validation is unsafe. " + "Please use a proper Certificate Authority to issue your TLS certificates."); + +/** + Initializes a web socket with a given `NSURLRequest`, list of sub-protocols and whether untrusted SSL certificates are allowed. + + @param request Request to initialize with. + @param protocols An array of strings that turn into `Sec-WebSocket-Protocol`. Default: `nil`. + @param securityPolicy Policy object describing transport security behavior. + */ +- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(nullable NSArray *)protocols securityPolicy:(SRSecurityPolicy *)securityPolicy NS_DESIGNATED_INITIALIZER; + +/** + Initializes a web socket with a given `NSURL`. + + @param url URL to initialize with. + */ +- (instancetype)initWithURL:(NSURL *)url; + +/** + Initializes a web socket with a given `NSURL` and list of sub-protocols. + + @param url URL to initialize with. + @param protocols An array of strings that turn into `Sec-WebSocket-Protocol`. Default: `nil`. + */ +- (instancetype)initWithURL:(NSURL *)url protocols:(nullable NSArray *)protocols; + +/** + Initializes a web socket with a given `NSURL`, specifying a transport security policy (e.g. SSL configuration). + + @param url URL to initialize with. + @param securityPolicy Policy object describing transport security behavior. + */ +- (instancetype)initWithURL:(NSURL *)url securityPolicy:(SRSecurityPolicy *)securityPolicy; + +/** + Initializes a web socket with a given `NSURL`, list of sub-protocols and whether untrusted SSL certificates are allowed. + + @param url URL to initialize with. + @param protocols An array of strings that turn into `Sec-WebSocket-Protocol`. Default: `nil`. + @param allowsUntrustedSSLCertificates Boolean value indicating whether untrusted SSL certificates are allowed. Default: `false`. + */ +- (instancetype)initWithURL:(NSURL *)url protocols:(nullable NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates + DEPRECATED_MSG_ATTRIBUTE("Disabling certificate chain validation is unsafe. " + "Please use a proper Certificate Authority to issue your TLS certificates."); + +/** + Unavailable initializer. Please use any other initializer. + */ +- (instancetype)init NS_UNAVAILABLE; + +/** + Unavailable constructor. Please use any other initializer. + */ ++ (instancetype)new NS_UNAVAILABLE; + +///-------------------------------------- +#pragma mark - Schedule +///-------------------------------------- + +/** + Schedules a received on a given run loop in a given mode. + By default, a web socket will schedule itself on `+[NSRunLoop SR_networkRunLoop]` using `NSDefaultRunLoopMode`. + + @param runLoop The run loop on which to schedule the receiver. + @param mode The mode for the run loop. + */ +- (void)scheduleInRunLoop:(NSRunLoop *)runLoop forMode:(NSString *)mode NS_SWIFT_NAME(schedule(in:forMode:)); + +/** + Removes the receiver from a given run loop running in a given mode. + + @param runLoop The run loop on which the receiver was scheduled. + @param mode The mode for the run loop. + */ +- (void)unscheduleFromRunLoop:(NSRunLoop *)runLoop forMode:(NSString *)mode NS_SWIFT_NAME(unschedule(from:forMode:)); + +///-------------------------------------- +#pragma mark - Open / Close +///-------------------------------------- + +/** + Opens web socket, which will trigger connection, authentication and start receiving/sending events. + An instance of `SRWebSocket` is intended for one-time-use only. This method should be called once and only once. + */ +- (void)open; + +/** + Closes a web socket using `SRStatusCodeNormal` code and no reason. + */ +- (void)close; + +/** + Closes a web socket using a given code and reason. + + @param code Code to close the socket with. + @param reason Reason to send to the server or `nil`. + */ +- (void)closeWithCode:(NSInteger)code reason:(nullable NSString *)reason; + +///-------------------------------------- +#pragma mark Send +///-------------------------------------- + +/** + Send a UTF-8 string or binary data to the server. + + @param message UTF-8 String or Data to send. + + @deprecated Please use `sendString:` or `sendData` instead. + */ +- (void)send:(nullable id)message __attribute__((deprecated("Please use `sendString:error:` or `sendData:error:` instead."))); + +/** + Send a UTF-8 String to the server. + + @param string String to send. + @param error On input, a pointer to variable for an `NSError` object. + If an error occurs, this pointer is set to an `NSError` object containing information about the error. + You may specify `nil` to ignore the error information. + + @return `YES` if the string was scheduled to send, otherwise - `NO`. + */ +- (BOOL)sendString:(NSString *)string error:(NSError **)error NS_SWIFT_NAME(send(string:)); + +/** + Send binary data to the server. + + @param data Data to send. + @param error On input, a pointer to variable for an `NSError` object. + If an error occurs, this pointer is set to an `NSError` object containing information about the error. + You may specify `nil` to ignore the error information. + + @return `YES` if the string was scheduled to send, otherwise - `NO`. + */ +- (BOOL)sendData:(nullable NSData *)data error:(NSError **)error NS_SWIFT_NAME(send(data:)); + +/** + Send binary data to the server, without making a defensive copy of it first. + + @param data Data to send. + @param error On input, a pointer to variable for an `NSError` object. + If an error occurs, this pointer is set to an `NSError` object containing information about the error. + You may specify `nil` to ignore the error information. + + @return `YES` if the string was scheduled to send, otherwise - `NO`. + */ +- (BOOL)sendDataNoCopy:(nullable NSData *)data error:(NSError **)error NS_SWIFT_NAME(send(dataNoCopy:)); + +/** + Send Ping message to the server with optional data. + + @param data Instance of `NSData` or `nil`. + @param error On input, a pointer to variable for an `NSError` object. + If an error occurs, this pointer is set to an `NSError` object containing information about the error. + You may specify `nil` to ignore the error information. + + @return `YES` if the string was scheduled to send, otherwise - `NO`. + */ +- (BOOL)sendPing:(nullable NSData *)data error:(NSError **)error NS_SWIFT_NAME(sendPing(_:)); + +@end + +///-------------------------------------- +#pragma mark - SRWebSocketDelegate +///-------------------------------------- + +/** + The `SRWebSocketDelegate` protocol describes the methods that `SRWebSocket` objects + call on their delegates to handle status and messsage events. + */ +@protocol SRWebSocketDelegate + +@optional + +#pragma mark Receive Messages + +/** + Called when any message was received from a web socket. + This method is suboptimal and might be deprecated in a future release. + + @param webSocket An instance of `SRWebSocket` that received a message. + @param message Received message. Either a `String` or `NSData`. + */ +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message; + +/** + Called when a frame was received from a web socket. + + @param webSocket An instance of `SRWebSocket` that received a message. + @param string Received text in a form of UTF-8 `String`. + */ +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithString:(NSString *)string; + +/** + Called when a frame was received from a web socket. + + @param webSocket An instance of `SRWebSocket` that received a message. + @param data Received data in a form of `NSData`. + */ +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithData:(NSData *)data; + +#pragma mark Status & Connection + +/** + Called when a given web socket was open and authenticated. + + @param webSocket An instance of `SRWebSocket` that was open. + */ +- (void)webSocketDidOpen:(SRWebSocket *)webSocket; + +/** + Called when a given web socket encountered an error. + + @param webSocket An instance of `SRWebSocket` that failed with an error. + @param error An instance of `NSError`. + */ +- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error; + +/** + Called when a given web socket was closed. + + @param webSocket An instance of `SRWebSocket` that was closed. + @param code Code reported by the server. + @param reason Reason in a form of a String that was reported by the server or `nil`. + @param wasClean Boolean value indicating whether a socket was closed in a clean state. + */ +- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(nullable NSString *)reason wasClean:(BOOL)wasClean; + +/** + Called on receive of a ping message from the server. + + @param webSocket An instance of `SRWebSocket` that received a ping frame. + @param data Payload that was received or `nil` if there was no payload. + */ +- (void)webSocket:(SRWebSocket *)webSocket didReceivePingWithData:(nullable NSData *)data; + +/** + Called when a pong data was received in response to ping. + + @param webSocket An instance of `SRWebSocket` that received a pong frame. + @param pongData Payload that was received or `nil` if there was no payload. + */ +- (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(nullable NSData *)pongData; + +/** + Sent before reporting a text frame to be able to configure if it shuold be convert to a UTF-8 String or passed as `NSData`. + If the method is not implemented - it will always convert text frames to String. + + @param webSocket An instance of `SRWebSocket` that received a text frame. + + @return `YES` if text frame should be converted to UTF-8 String, otherwise - `NO`. Default: `YES`. + */ +- (BOOL)webSocketShouldConvertTextFrameToString:(SRWebSocket *)webSocket NS_SWIFT_NAME(webSocketShouldConvertTextFrameToString(_:)); + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/SocketRocket/SRWebSocket.m b/Sources/Vendor/SocketRocket/SocketRocket/SRWebSocket.m new file mode 100755 index 0000000..c0e96f7 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/SRWebSocket.m @@ -0,0 +1,1628 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRWebSocket.h" + +#if TARGET_OS_IPHONE +#define HAS_ICU +#endif + +#ifdef HAS_ICU +#import +#endif + +#import + +#import "SRDelegateController.h" +#import "SRIOConsumer.h" +#import "SRIOConsumerPool.h" +#import "SRHash.h" +#import "SRURLUtilities.h" +#import "SRError.h" +#import "NSURLRequest+SRWebSocket.h" +#import "NSRunLoop+SRWebSocket.h" +#import "SRProxyConnect.h" +#import "SRSecurityPolicy.h" +#import "SRHTTPConnectMessage.h" +#import "SRRandom.h" +#import "SRLog.h" +#import "SRMutex.h" +#import "SRSIMDHelpers.h" +#import "NSURLRequest+SRWebSocketPrivate.h" +#import "NSRunLoop+SRWebSocketPrivate.h" +#import "SRConstants.h" + +#if !__has_feature(objc_arc) +#error SocketRocket must be compiled with ARC enabled +#endif + +__attribute__((used)) static void importCategories() +{ + import_NSURLRequest_SRWebSocket(); + import_NSRunLoop_SRWebSocket(); +} + +typedef struct { + BOOL fin; + // BOOL rsv1; + // BOOL rsv2; + // BOOL rsv3; + uint8_t opcode; + BOOL masked; + uint64_t payload_length; +} frame_header; + +static NSString *const SRWebSocketAppendToSecKeyString = @"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; + +static inline int32_t validate_dispatch_data_partial_string(NSData *data); + +static uint8_t const SRWebSocketProtocolVersion = 13; + +NSString *const SRWebSocketErrorDomain = @"SRWebSocketErrorDomain"; +NSString *const SRHTTPResponseErrorKey = @"HTTPResponseStatusCode"; + +@interface SRWebSocket () + +@property (atomic, assign, readwrite) SRReadyState readyState; + +// Specifies whether SSL trust chain should NOT be evaluated. +// By default this flag is set to NO, meaning only secure SSL connections are allowed. +// For DEBUG builds this flag is ignored, and SSL connections are allowed regardless +// of the certificate trust configuration +@property (nonatomic, assign, readwrite) BOOL allowsUntrustedSSLCertificates; + +@property (nonatomic, strong, readonly) SRDelegateController *delegateController; + +@end + +@implementation SRWebSocket { + SRMutex _kvoLock; + OSSpinLock _propertyLock; + + dispatch_queue_t _workQueue; + NSMutableArray *_consumers; + + NSInputStream *_inputStream; + NSOutputStream *_outputStream; + + dispatch_data_t _readBuffer; + NSUInteger _readBufferOffset; + + dispatch_data_t _outputBuffer; + NSUInteger _outputBufferOffset; + + uint8_t _currentFrameOpcode; + size_t _currentFrameCount; + size_t _readOpCount; + uint32_t _currentStringScanPosition; + NSMutableData *_currentFrameData; + + NSString *_closeReason; + + NSString *_secKey; + + SRSecurityPolicy *_securityPolicy; + BOOL _requestRequiresSSL; + BOOL _streamSecurityValidated; + + uint8_t _currentReadMaskKey[4]; + size_t _currentReadMaskOffset; + + BOOL _closeWhenFinishedWriting; + BOOL _failed; + + NSURLRequest *_urlRequest; + + BOOL _sentClose; + BOOL _didFail; + BOOL _cleanupScheduled; + int _closeCode; + + BOOL _isPumping; + + NSMutableSet *_scheduledRunloops; // Set<[RunLoop, Mode]>. TODO: (nlutsenko) Fix clowntown + + // We use this to retain ourselves. + __strong SRWebSocket *_selfRetain; + + NSArray *_requestedProtocols; + SRIOConsumerPool *_consumerPool; + + // proxy support + SRProxyConnect *_proxyConnect; +} + +@synthesize readyState = _readyState; + +///-------------------------------------- +#pragma mark - Init +///-------------------------------------- + +- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols securityPolicy:(SRSecurityPolicy *)securityPolicy +{ + self = [super init]; + if (!self) return self; + + assert(request.URL); + _url = request.URL; + _urlRequest = request; + _requestedProtocols = [protocols copy]; + _securityPolicy = securityPolicy; + _requestRequiresSSL = SRURLRequiresSSL(_url); + + _readyState = SR_CONNECTING; + + _propertyLock = OS_SPINLOCK_INIT; + _kvoLock = SRMutexInitRecursive(); + _workQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); + + // Going to set a specific on the queue so we can validate we're on the work queue + dispatch_queue_set_specific(_workQueue, (__bridge void *)self, (__bridge void *)(_workQueue), NULL); + + _delegateController = [[SRDelegateController alloc] init]; + + _readBuffer = dispatch_data_empty; + _outputBuffer = dispatch_data_empty; + + _currentFrameData = [[NSMutableData alloc] init]; + + _consumers = [[NSMutableArray alloc] init]; + + _consumerPool = [[SRIOConsumerPool alloc] init]; + + _scheduledRunloops = [[NSMutableSet alloc] init]; + + return self; +} + +- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates +{ + SRSecurityPolicy *securityPolicy; + BOOL certificateChainValidationEnabled = !allowsUntrustedSSLCertificates; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated" + + securityPolicy = [[SRSecurityPolicy alloc] initWithCertificateChainValidationEnabled:certificateChainValidationEnabled]; + +#pragma clang diagnostic pop + + return [self initWithURLRequest:request protocols:protocols securityPolicy:securityPolicy]; +} + +- (instancetype)initWithURLRequest:(NSURLRequest *)request securityPolicy:(SRSecurityPolicy *)securityPolicy +{ + return [self initWithURLRequest:request protocols:nil securityPolicy:securityPolicy]; +} + +- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols +{ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated" + + return [self initWithURLRequest:request protocols:protocols allowsUntrustedSSLCertificates:NO]; + +#pragma clang diagnostic pop +} + +- (instancetype)initWithURLRequest:(NSURLRequest *)request +{ + return [self initWithURLRequest:request protocols:nil]; +} + +- (instancetype)initWithURL:(NSURL *)url; +{ + return [self initWithURL:url protocols:nil]; +} + +- (instancetype)initWithURL:(NSURL *)url protocols:(NSArray *)protocols; +{ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated" + + return [self initWithURL:url protocols:protocols allowsUntrustedSSLCertificates:NO]; + +#pragma clang diagnostic pop +} + +- (instancetype)initWithURL:(NSURL *)url securityPolicy:(SRSecurityPolicy *)securityPolicy +{ + NSURLRequest *request = [NSURLRequest requestWithURL:url]; + return [self initWithURLRequest:request protocols:nil securityPolicy:securityPolicy]; +} + +- (instancetype)initWithURL:(NSURL *)url protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates +{ + NSURLRequest *request = [NSURLRequest requestWithURL:url]; + return [self initWithURLRequest:request protocols:protocols allowsUntrustedSSLCertificates:allowsUntrustedSSLCertificates]; +} + +- (void)assertOnWorkQueue; +{ + assert(dispatch_get_specific((__bridge void *)self) == (__bridge void *)_workQueue); +} + +///-------------------------------------- +#pragma mark - Dealloc +///-------------------------------------- + +- (void)dealloc +{ + _inputStream.delegate = nil; + _outputStream.delegate = nil; + + [_inputStream close]; + [_outputStream close]; + + if (_receivedHTTPHeaders) { + CFRelease(_receivedHTTPHeaders); + _receivedHTTPHeaders = NULL; + } + + SRMutexDestroy(_kvoLock); +} + +///-------------------------------------- +#pragma mark - Accessors +///-------------------------------------- + +#pragma mark readyState + +- (void)setReadyState:(SRReadyState)readyState +{ + @try { + SRMutexLock(_kvoLock); + if (_readyState != readyState) { + [self willChangeValueForKey:@"readyState"]; + OSSpinLockLock(&_propertyLock); + _readyState = readyState; + OSSpinLockUnlock(&_propertyLock); + [self didChangeValueForKey:@"readyState"]; + } + } + @finally { + SRMutexUnlock(_kvoLock); + } +} + +- (SRReadyState)readyState +{ + SRReadyState state = 0; + OSSpinLockLock(&_propertyLock); + state = _readyState; + OSSpinLockUnlock(&_propertyLock); + return state; +} + ++ (BOOL)automaticallyNotifiesObserversOfReadyState { + return NO; +} + +///-------------------------------------- +#pragma mark - Open / Close +///-------------------------------------- + +- (void)open +{ + assert(_url); + NSAssert(self.readyState == SR_CONNECTING, @"Cannot call -(void)open on SRWebSocket more than once."); + + _selfRetain = self; + + if (_urlRequest.timeoutInterval > 0) { + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_urlRequest.timeoutInterval * NSEC_PER_SEC)); + dispatch_after(popTime, dispatch_get_main_queue(), ^{ + if (self.readyState == SR_CONNECTING) { + NSError *error = SRErrorWithDomainCodeDescription(NSURLErrorDomain, NSURLErrorTimedOut, @"Timed out connecting to server."); + [self _failWithError:error]; + } + }); + } + + _proxyConnect = [[SRProxyConnect alloc] initWithURL:_url]; + + __weak typeof(self) wself = self; + [_proxyConnect openNetworkStreamWithCompletion:^(NSError *error, NSInputStream *readStream, NSOutputStream *writeStream) { + [wself _connectionDoneWithError:error readStream:readStream writeStream:writeStream]; + }]; +} + +- (void)_connectionDoneWithError:(NSError *)error readStream:(NSInputStream *)readStream writeStream:(NSOutputStream *)writeStream +{ + if (error != nil) { + [self _failWithError:error]; + } else { + _outputStream = writeStream; + _inputStream = readStream; + + _inputStream.delegate = self; + _outputStream.delegate = self; + [self _updateSecureStreamOptions]; + + if (!_scheduledRunloops.count) { + [self scheduleInRunLoop:[NSRunLoop SR_networkRunLoop] forMode:NSDefaultRunLoopMode]; + } + + // If we don't require SSL validation - consider that we connected. + // Otherwise `didConnect` is called when SSL validation finishes. + if (!_requestRequiresSSL) { + dispatch_async(_workQueue, ^{ + [self didConnect]; + }); + } + } + // Schedule to run on a work queue, to make sure we don't run this inline and deallocate `self` inside `SRProxyConnect`. + // TODO: (nlutsenko) Find a better structure for this, maybe Bolts Tasks? + dispatch_async(_workQueue, ^{ + _proxyConnect = nil; + }); +} + +- (BOOL)_checkHandshake:(CFHTTPMessageRef)httpMessage; +{ + NSString *acceptHeader = CFBridgingRelease(CFHTTPMessageCopyHeaderFieldValue(httpMessage, CFSTR("Sec-WebSocket-Accept"))); + + if (acceptHeader == nil) { + return NO; + } + + NSString *concattedString = [_secKey stringByAppendingString:SRWebSocketAppendToSecKeyString]; + NSData *hashedString = SRSHA1HashFromString(concattedString); + NSString *expectedAccept = SRBase64EncodedStringFromData(hashedString); + return [acceptHeader isEqualToString:expectedAccept]; +} + +- (void)_HTTPHeadersDidFinish; +{ + NSInteger responseCode = CFHTTPMessageGetResponseStatusCode(_receivedHTTPHeaders); + if (responseCode >= 400) { + SRDebugLog(@"Request failed with response code %d", responseCode); + NSError *error = SRHTTPErrorWithCodeDescription(responseCode, 2132, + [NSString stringWithFormat:@"Received bad response code from server: %d.", + (int)responseCode]); + [self _failWithError:error]; + return; + } + + if(![self _checkHandshake:_receivedHTTPHeaders]) { + NSError *error = SRErrorWithCodeDescription(2133, @"Invalid Sec-WebSocket-Accept response."); + [self _failWithError:error]; + return; + } + + NSString *negotiatedProtocol = CFBridgingRelease(CFHTTPMessageCopyHeaderFieldValue(_receivedHTTPHeaders, CFSTR("Sec-WebSocket-Protocol"))); + if (negotiatedProtocol) { + // Make sure we requested the protocol + if ([_requestedProtocols indexOfObject:negotiatedProtocol] == NSNotFound) { + NSError *error = SRErrorWithCodeDescription(2133, @"Server specified Sec-WebSocket-Protocol that wasn't requested."); + [self _failWithError:error]; + return; + } + + _protocol = negotiatedProtocol; + } + + self.readyState = SR_OPEN; + + if (!_didFail) { + [self _readFrameNew]; + } + + [self.delegateController performDelegateBlock:^(id _Nullable delegate, SRDelegateAvailableMethods availableMethods) { + if (availableMethods.didOpen) { + [delegate webSocketDidOpen:self]; + } + }]; +} + + +- (void)_readHTTPHeader; +{ + if (_receivedHTTPHeaders == NULL) { + _receivedHTTPHeaders = CFHTTPMessageCreateEmpty(NULL, NO); + } + + [self _readUntilHeaderCompleteWithCallback:^(SRWebSocket *socket, NSData *data) { + CFHTTPMessageAppendBytes(_receivedHTTPHeaders, (const UInt8 *)data.bytes, data.length); + + if (CFHTTPMessageIsHeaderComplete(_receivedHTTPHeaders)) { + SRDebugLog(@"Finished reading headers %@", CFBridgingRelease(CFHTTPMessageCopyAllHeaderFields(_receivedHTTPHeaders))); + [self _HTTPHeadersDidFinish]; + } else { + [self _readHTTPHeader]; + } + }]; +} + +- (void)didConnect; +{ + SRDebugLog(@"Connected"); + + _secKey = SRBase64EncodedStringFromData(SRRandomData(16)); + assert([_secKey length] == 24); + + CFHTTPMessageRef message = SRHTTPConnectMessageCreate(_urlRequest, + _secKey, + SRWebSocketProtocolVersion, + self.requestCookies, + _requestedProtocols); + + NSData *messageData = CFBridgingRelease(CFHTTPMessageCopySerializedMessage(message)); + + CFRelease(message); + + [self _writeData:messageData]; + [self _readHTTPHeader]; +} + +- (void)_updateSecureStreamOptions +{ + if (_requestRequiresSSL) { + SRDebugLog(@"Setting up security for streams."); + [_securityPolicy updateSecurityOptionsInStream:_inputStream]; + [_securityPolicy updateSecurityOptionsInStream:_outputStream]; + } + + NSString *networkServiceType = SRStreamNetworkServiceTypeFromURLRequest(_urlRequest); + if (networkServiceType != nil) { + [_inputStream setProperty:networkServiceType forKey:NSStreamNetworkServiceType]; + [_outputStream setProperty:networkServiceType forKey:NSStreamNetworkServiceType]; + } +} + +- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode; +{ + [_outputStream scheduleInRunLoop:aRunLoop forMode:mode]; + [_inputStream scheduleInRunLoop:aRunLoop forMode:mode]; + + [_scheduledRunloops addObject:@[aRunLoop, mode]]; +} + +- (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode; +{ + [_outputStream removeFromRunLoop:aRunLoop forMode:mode]; + [_inputStream removeFromRunLoop:aRunLoop forMode:mode]; + + [_scheduledRunloops removeObject:@[aRunLoop, mode]]; +} + +- (void)close; +{ + [self closeWithCode:SRStatusCodeNormal reason:nil]; +} + +- (void)closeWithCode:(NSInteger)code reason:(NSString *)reason; +{ + assert(code); + dispatch_async(_workQueue, ^{ + if (self.readyState == SR_CLOSING || self.readyState == SR_CLOSED) { + return; + } + + BOOL wasConnecting = self.readyState == SR_CONNECTING; + + self.readyState = SR_CLOSING; + + SRDebugLog(@"Closing with code %d reason %@", code, reason); + + if (wasConnecting) { + [self closeConnection]; + return; + } + + size_t maxMsgSize = [reason maximumLengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + NSMutableData *mutablePayload = [[NSMutableData alloc] initWithLength:sizeof(uint16_t) + maxMsgSize]; + NSData *payload = mutablePayload; + + ((uint16_t *)mutablePayload.mutableBytes)[0] = CFSwapInt16BigToHost((uint16_t)code); + + if (reason) { + NSRange remainingRange = {0}; + + NSUInteger usedLength = 0; + + BOOL success = [reason getBytes:(char *)mutablePayload.mutableBytes + sizeof(uint16_t) maxLength:payload.length - sizeof(uint16_t) usedLength:&usedLength encoding:NSUTF8StringEncoding options:NSStringEncodingConversionExternalRepresentation range:NSMakeRange(0, reason.length) remainingRange:&remainingRange]; +#pragma unused (success) + + assert(success); + assert(remainingRange.length == 0); + + if (usedLength != maxMsgSize) { + payload = [payload subdataWithRange:NSMakeRange(0, usedLength + sizeof(uint16_t))]; + } + } + + + [self _sendFrameWithOpcode:SROpCodeConnectionClose data:payload]; + }); +} + +- (void)_closeWithProtocolError:(NSString *)message; +{ + // Need to shunt this on the _callbackQueue first to see if they received any messages + [self.delegateController performDelegateQueueBlock:^{ + [self closeWithCode:SRStatusCodeProtocolError reason:message]; + dispatch_async(_workQueue, ^{ + [self closeConnection]; + }); + }]; +} + +- (void)_failWithError:(NSError *)error; +{ + dispatch_async(_workQueue, ^{ + if (self.readyState != SR_CLOSED) { + _failed = YES; + [self.delegateController performDelegateBlock:^(id _Nullable delegate, SRDelegateAvailableMethods availableMethods) { + if (availableMethods.didFailWithError) { + [delegate webSocket:self didFailWithError:error]; + } + }]; + + self.readyState = SR_CLOSED; + + SRDebugLog(@"Failing with error %@", error.localizedDescription); + + [self closeConnection]; + [self _scheduleCleanup]; + } + }); +} + +- (void)_writeData:(NSData *)data; +{ + [self assertOnWorkQueue]; + + if (_closeWhenFinishedWriting) { + return; + } + + __block NSData *strongData = data; + dispatch_data_t newData = dispatch_data_create(data.bytes, data.length, nil, ^{ + strongData = nil; + }); + _outputBuffer = dispatch_data_create_concat(_outputBuffer, newData); + [self _pumpWriting]; +} + +- (void)send:(nullable id)message +{ + if (!message) { + [self sendData:nil error:nil]; // Send Data, but it doesn't matter since we are going to send the same text frame with 0 length. + } else if ([message isKindOfClass:[NSString class]]) { + [self sendString:message error:nil]; + } else if ([message isKindOfClass:[NSData class]]) { + [self sendData:message error:nil]; + } else { + NSAssert(NO, @"Unrecognized message. Not able to send anything other than a String or NSData."); + } +} + +- (BOOL)sendString:(NSString *)string error:(NSError **)error +{ + if (self.readyState != SR_OPEN) { + NSString *message = @"Invalid State: Cannot call `sendString:error:` until connection is open."; + if (error) { + *error = SRErrorWithCodeDescription(2134, message); + } + SRDebugLog(message); + return NO; + } + + string = [string copy]; + dispatch_async(_workQueue, ^{ + [self _sendFrameWithOpcode:SROpCodeTextFrame data:[string dataUsingEncoding:NSUTF8StringEncoding]]; + }); + return YES; +} + +- (BOOL)sendData:(nullable NSData *)data error:(NSError **)error +{ + data = [data copy]; + return [self sendDataNoCopy:data error:error]; +} + +- (BOOL)sendDataNoCopy:(nullable NSData *)data error:(NSError **)error +{ + if (self.readyState != SR_OPEN) { + NSString *message = @"Invalid State: Cannot call `sendDataNoCopy:error:` until connection is open."; + if (error) { + *error = SRErrorWithCodeDescription(2134, message); + } + SRDebugLog(message); + return NO; + } + + dispatch_async(_workQueue, ^{ + if (data) { + [self _sendFrameWithOpcode:SROpCodeBinaryFrame data:data]; + } else { + [self _sendFrameWithOpcode:SROpCodeTextFrame data:nil]; + } + }); + return YES; +} + +- (BOOL)sendPing:(nullable NSData *)data error:(NSError **)error +{ + if (self.readyState != SR_OPEN) { + NSString *message = @"Invalid State: Cannot call `sendPing:error:` until connection is open."; + if (error) { + *error = SRErrorWithCodeDescription(2134, message); + } + SRDebugLog(message); + return NO; + } + + data = [data copy] ?: [NSData data]; // It's okay for a ping to be empty + dispatch_async(_workQueue, ^{ + [self _sendFrameWithOpcode:SROpCodePing data:data]; + }); + return YES; +} + +- (void)_handlePingWithData:(nullable NSData *)data +{ + // Need to pingpong this off _callbackQueue first to make sure messages happen in order + [self.delegateController performDelegateBlock:^(id _Nullable delegate, SRDelegateAvailableMethods availableMethods) { + if (availableMethods.didReceivePing) { + [delegate webSocket:self didReceivePingWithData:data]; + } + dispatch_async(_workQueue, ^{ + [self _sendFrameWithOpcode:SROpCodePong data:data]; + }); + }]; +} + +- (void)handlePong:(NSData *)pongData; +{ + SRDebugLog(@"Received pong"); + [self.delegateController performDelegateBlock:^(id _Nullable delegate, SRDelegateAvailableMethods availableMethods) { + if (availableMethods.didReceivePong) { + [delegate webSocket:self didReceivePong:pongData]; + } + }]; +} + + +static inline BOOL closeCodeIsValid(int closeCode) { + if (closeCode < 1000) { + return NO; + } + + if (closeCode >= 1000 && closeCode <= 1011) { + if (closeCode == 1004 || + closeCode == 1005 || + closeCode == 1006) { + return NO; + } + return YES; + } + + if (closeCode >= 3000 && closeCode <= 3999) { + return YES; + } + + if (closeCode >= 4000 && closeCode <= 4999) { + return YES; + } + + return NO; +} + +// Note from RFC: +// +// If there is a body, the first two +// bytes of the body MUST be a 2-byte unsigned integer (in network byte +// order) representing a status code with value /code/ defined in +// Section 7.4. Following the 2-byte integer the body MAY contain UTF-8 +// encoded data with value /reason/, the interpretation of which is not +// defined by this specification. + +- (void)handleCloseWithData:(NSData *)data; +{ + size_t dataSize = data.length; + __block uint16_t closeCode = 0; + + SRDebugLog(@"Received close frame"); + + if (dataSize == 1) { + // TODO handle error + [self _closeWithProtocolError:@"Payload for close must be larger than 2 bytes"]; + return; + } else if (dataSize >= 2) { + [data getBytes:&closeCode length:sizeof(closeCode)]; + _closeCode = CFSwapInt16BigToHost(closeCode); + if (!closeCodeIsValid(_closeCode)) { + [self _closeWithProtocolError:[NSString stringWithFormat:@"Cannot have close code of %d", _closeCode]]; + return; + } + if (dataSize > 2) { + _closeReason = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(2, dataSize - 2)] encoding:NSUTF8StringEncoding]; + if (!_closeReason) { + [self _closeWithProtocolError:@"Close reason MUST be valid UTF-8"]; + return; + } + } + } else { + _closeCode = SRStatusNoStatusReceived; + } + + [self assertOnWorkQueue]; + + if (self.readyState == SR_OPEN) { + [self closeWithCode:1000 reason:nil]; + } + dispatch_async(_workQueue, ^{ + [self closeConnection]; + }); +} + +- (void)closeConnection; +{ + [self assertOnWorkQueue]; + SRDebugLog(@"Trying to disconnect"); + _closeWhenFinishedWriting = YES; + [self _pumpWriting]; +} + +- (void)_handleFrameWithData:(NSData *)frameData opCode:(SROpCode)opcode +{ + // Check that the current data is valid UTF8 + + BOOL isControlFrame = (opcode == SROpCodePing || opcode == SROpCodePong || opcode == SROpCodeConnectionClose); + if (isControlFrame) { + //frameData will be copied before passing to handlers + //otherwise there can be misbehaviours when value at the pointer is changed + frameData = [frameData copy]; + + dispatch_async(_workQueue, ^{ + [self _readFrameContinue]; + }); + } else { + [self _readFrameNew]; + } + + switch (opcode) { + case SROpCodeTextFrame: { + NSString *string = [[NSString alloc] initWithData:frameData encoding:NSUTF8StringEncoding]; + if (!string && frameData) { + [self closeWithCode:SRStatusCodeInvalidUTF8 reason:@"Text frames must be valid UTF-8."]; + dispatch_async(_workQueue, ^{ + [self closeConnection]; + }); + return; + } + SRDebugLog(@"Received text message."); + [self.delegateController performDelegateBlock:^(id _Nullable delegate, SRDelegateAvailableMethods availableMethods) { + // Don't convert into string - iff `delegate` tells us not to. Otherwise - create UTF8 string and handle that. + if (availableMethods.shouldConvertTextFrameToString && ![delegate webSocketShouldConvertTextFrameToString:self]) { + if (availableMethods.didReceiveMessage) { + [delegate webSocket:self didReceiveMessage:frameData]; + } + if (availableMethods.didReceiveMessageWithData) { + [delegate webSocket:self didReceiveMessageWithData:frameData]; + } + } else { + if (availableMethods.didReceiveMessage) { + [delegate webSocket:self didReceiveMessage:string]; + } + if (availableMethods.didReceiveMessageWithString) { + [delegate webSocket:self didReceiveMessageWithString:string]; + } + } + }]; + break; + } + case SROpCodeBinaryFrame: { + SRDebugLog(@"Received data message."); + [self.delegateController performDelegateBlock:^(id _Nullable delegate, SRDelegateAvailableMethods availableMethods) { + if (availableMethods.didReceiveMessage) { + [delegate webSocket:self didReceiveMessage:frameData]; + } + if (availableMethods.didReceiveMessageWithData) { + [delegate webSocket:self didReceiveMessageWithData:frameData]; + } + }]; + } + break; + case SROpCodeConnectionClose: + [self handleCloseWithData:frameData]; + break; + case SROpCodePing: + [self _handlePingWithData:frameData]; + break; + case SROpCodePong: + [self handlePong:frameData]; + break; + default: + [self _closeWithProtocolError:[NSString stringWithFormat:@"Unknown opcode %ld", (long)opcode]]; + // TODO: Handle invalid opcode + break; + } +} + +- (void)_handleFrameHeader:(frame_header)frame_header curData:(NSData *)curData; +{ + assert(frame_header.opcode != 0); + + if (self.readyState == SR_CLOSED) { + return; + } + + + BOOL isControlFrame = (frame_header.opcode == SROpCodePing || frame_header.opcode == SROpCodePong || frame_header.opcode == SROpCodeConnectionClose); + + if (isControlFrame && !frame_header.fin) { + [self _closeWithProtocolError:@"Fragmented control frames not allowed"]; + return; + } + + if (isControlFrame && frame_header.payload_length >= 126) { + [self _closeWithProtocolError:@"Control frames cannot have payloads larger than 126 bytes"]; + return; + } + + if (!isControlFrame) { + _currentFrameOpcode = frame_header.opcode; + _currentFrameCount += 1; + } + + if (frame_header.payload_length == 0) { + if (isControlFrame) { + [self _handleFrameWithData:curData opCode:frame_header.opcode]; + } else { + if (frame_header.fin) { + [self _handleFrameWithData:_currentFrameData opCode:frame_header.opcode]; + } else { + // TODO add assert that opcode is not a control; + [self _readFrameContinue]; + } + } + } else { + assert(frame_header.payload_length <= SIZE_T_MAX); + [self _addConsumerWithDataLength:(size_t)frame_header.payload_length callback:^(SRWebSocket *sself, NSData *newData) { + if (isControlFrame) { + [sself _handleFrameWithData:newData opCode:frame_header.opcode]; + } else { + if (frame_header.fin) { + [sself _handleFrameWithData:sself->_currentFrameData opCode:frame_header.opcode]; + } else { + // TODO add assert that opcode is not a control; + [sself _readFrameContinue]; + } + } + } readToCurrentFrame:!isControlFrame unmaskBytes:frame_header.masked]; + } +} + +/* From RFC: + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-------+-+-------------+-------------------------------+ + |F|R|R|R| opcode|M| Payload len | Extended payload length | + |I|S|S|S| (4) |A| (7) | (16/64) | + |N|V|V|V| |S| | (if payload len==126/127) | + | |1|2|3| |K| | | + +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - + + | Extended payload length continued, if payload len == 127 | + + - - - - - - - - - - - - - - - +-------------------------------+ + | |Masking-key, if MASK set to 1 | + +-------------------------------+-------------------------------+ + | Masking-key (continued) | Payload Data | + +-------------------------------- - - - - - - - - - - - - - - - + + : Payload Data continued ... : + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + | Payload Data continued ... | + +---------------------------------------------------------------+ + */ + +static const uint8_t SRFinMask = 0x80; +static const uint8_t SROpCodeMask = 0x0F; +static const uint8_t SRRsvMask = 0x70; +static const uint8_t SRMaskMask = 0x80; +static const uint8_t SRPayloadLenMask = 0x7F; + + +- (void)_readFrameContinue; +{ + assert((_currentFrameCount == 0 && _currentFrameOpcode == 0) || (_currentFrameCount > 0 && _currentFrameOpcode > 0)); + + [self _addConsumerWithDataLength:2 callback:^(SRWebSocket *sself, NSData *data) { + __block frame_header header = {0}; + + const uint8_t *headerBuffer = data.bytes; + assert(data.length >= 2); + + if (headerBuffer[0] & SRRsvMask) { + [sself _closeWithProtocolError:@"Server used RSV bits"]; + return; + } + + uint8_t receivedOpcode = (SROpCodeMask & headerBuffer[0]); + + BOOL isControlFrame = (receivedOpcode == SROpCodePing || receivedOpcode == SROpCodePong || receivedOpcode == SROpCodeConnectionClose); + + if (!isControlFrame && receivedOpcode != 0 && sself->_currentFrameCount > 0) { + [sself _closeWithProtocolError:@"all data frames after the initial data frame must have opcode 0"]; + return; + } + + if (receivedOpcode == 0 && sself->_currentFrameCount == 0) { + [sself _closeWithProtocolError:@"cannot continue a message"]; + return; + } + + header.opcode = receivedOpcode == 0 ? sself->_currentFrameOpcode : receivedOpcode; + + header.fin = !!(SRFinMask & headerBuffer[0]); + + + header.masked = !!(SRMaskMask & headerBuffer[1]); + header.payload_length = SRPayloadLenMask & headerBuffer[1]; + + headerBuffer = NULL; + + if (header.masked) { + [sself _closeWithProtocolError:@"Client must receive unmasked data"]; + return; + } + + size_t extra_bytes_needed = header.masked ? sizeof(_currentReadMaskKey) : 0; + + if (header.payload_length == 126) { + extra_bytes_needed += sizeof(uint16_t); + } else if (header.payload_length == 127) { + extra_bytes_needed += sizeof(uint64_t); + } + + if (extra_bytes_needed == 0) { + [sself _handleFrameHeader:header curData:sself->_currentFrameData]; + } else { + [sself _addConsumerWithDataLength:extra_bytes_needed callback:^(SRWebSocket *eself, NSData *edata) { + size_t mapped_size = edata.length; +#pragma unused (mapped_size) + const void *mapped_buffer = edata.bytes; + size_t offset = 0; + + if (header.payload_length == 126) { + assert(mapped_size >= sizeof(uint16_t)); + uint16_t payloadLength = 0; + memcpy(&payloadLength, mapped_buffer, sizeof(uint16_t)); + payloadLength = CFSwapInt16BigToHost(payloadLength); + + header.payload_length = payloadLength; + offset += sizeof(uint16_t); + } else if (header.payload_length == 127) { + assert(mapped_size >= sizeof(uint64_t)); + uint64_t payloadLength = 0; + memcpy(&payloadLength, mapped_buffer, sizeof(uint64_t)); + payloadLength = CFSwapInt64BigToHost(payloadLength); + + header.payload_length = payloadLength; + offset += sizeof(uint64_t); + } else { + assert(header.payload_length < 126 && header.payload_length >= 0); + } + + if (header.masked) { + assert(mapped_size >= sizeof(_currentReadMaskOffset) + offset); + memcpy(eself->_currentReadMaskKey, ((uint8_t *)mapped_buffer) + offset, sizeof(eself->_currentReadMaskKey)); + } + + [eself _handleFrameHeader:header curData:eself->_currentFrameData]; + } readToCurrentFrame:NO unmaskBytes:NO]; + } + } readToCurrentFrame:NO unmaskBytes:NO]; +} + +- (void)_readFrameNew; +{ + dispatch_async(_workQueue, ^{ + // Don't reset the length, since Apple doesn't guarantee that this will free the memory (and in tests on + // some platforms, it doesn't seem to, effectively causing a leak the size of the biggest frame so far). + _currentFrameData = [[NSMutableData alloc] init]; + + _currentFrameOpcode = 0; + _currentFrameCount = 0; + _readOpCount = 0; + _currentStringScanPosition = 0; + + [self _readFrameContinue]; + }); +} + +- (void)_pumpWriting; +{ + [self assertOnWorkQueue]; + + NSUInteger dataLength = dispatch_data_get_size(_outputBuffer); + if (dataLength - _outputBufferOffset > 0 && _outputStream.hasSpaceAvailable) { + __block NSInteger bytesWritten = 0; + __block BOOL streamFailed = NO; + + dispatch_data_t dataToSend = dispatch_data_create_subrange(_outputBuffer, _outputBufferOffset, dataLength - _outputBufferOffset); + dispatch_data_apply(dataToSend, ^bool(dispatch_data_t region, size_t offset, const void *buffer, size_t size) { + NSInteger sentLength = [_outputStream write:buffer maxLength:size]; + if (sentLength == -1) { + streamFailed = YES; + return false; + } + bytesWritten += sentLength; + return (sentLength >= (NSInteger)size); // If we can't write all the data into the stream - bail-out early. + }); + if (streamFailed) { + NSInteger code = 2145; + NSString *description = @"Error writing to stream."; + NSError *streamError = _outputStream.streamError; + NSError *error = streamError ? SRErrorWithCodeDescriptionUnderlyingError(code, description, streamError) : SRErrorWithCodeDescription(code, description); + [self _failWithError:error]; + return; + } + + _outputBufferOffset += bytesWritten; + + if (_outputBufferOffset > SRDefaultBufferSize() && _outputBufferOffset > dataLength / 2) { + _outputBuffer = dispatch_data_create_subrange(_outputBuffer, _outputBufferOffset, dataLength - _outputBufferOffset); + _outputBufferOffset = 0; + } + } + + if (_closeWhenFinishedWriting && + (dispatch_data_get_size(_outputBuffer) - _outputBufferOffset) == 0 && + (_inputStream.streamStatus != NSStreamStatusNotOpen && + _inputStream.streamStatus != NSStreamStatusClosed) && + !_sentClose) { + _sentClose = YES; + + @synchronized(self) { + [_outputStream close]; + [_inputStream close]; + + + for (NSArray *runLoop in [_scheduledRunloops copy]) { + [self unscheduleFromRunLoop:[runLoop objectAtIndex:0] forMode:[runLoop objectAtIndex:1]]; + } + } + + if (!_failed) { + [self.delegateController performDelegateBlock:^(id _Nullable delegate, SRDelegateAvailableMethods availableMethods) { + if (availableMethods.didCloseWithCode) { + [delegate webSocket:self didCloseWithCode:_closeCode reason:_closeReason wasClean:YES]; + } + }]; + } + + [self _scheduleCleanup]; + } +} + +- (void)_addConsumerWithScanner:(stream_scanner)consumer callback:(data_callback)callback; +{ + [self assertOnWorkQueue]; + [self _addConsumerWithScanner:consumer callback:callback dataLength:0]; +} + +- (void)_addConsumerWithDataLength:(size_t)dataLength callback:(data_callback)callback readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes; +{ + [self assertOnWorkQueue]; + assert(dataLength); + + [_consumers addObject:[_consumerPool consumerWithScanner:nil handler:callback bytesNeeded:dataLength readToCurrentFrame:readToCurrentFrame unmaskBytes:unmaskBytes]]; + [self _pumpScanner]; +} + +- (void)_addConsumerWithScanner:(stream_scanner)consumer callback:(data_callback)callback dataLength:(size_t)dataLength; +{ + [self assertOnWorkQueue]; + [_consumers addObject:[_consumerPool consumerWithScanner:consumer handler:callback bytesNeeded:dataLength readToCurrentFrame:NO unmaskBytes:NO]]; + [self _pumpScanner]; +} + + +- (void)_scheduleCleanup +{ + @synchronized(self) { + if (_cleanupScheduled) { + return; + } + + _cleanupScheduled = YES; + + // Cleanup NSStream delegate's in the same RunLoop used by the streams themselves: + // This way we'll prevent race conditions between handleEvent and SRWebsocket's dealloc + NSTimer *timer = [NSTimer timerWithTimeInterval:(0.0f) target:self selector:@selector(_cleanupSelfReference:) userInfo:nil repeats:NO]; + [[NSRunLoop SR_networkRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode]; + } +} + +- (void)_cleanupSelfReference:(NSTimer *)timer +{ + @synchronized(self) { + // Nuke NSStream delegate's + _inputStream.delegate = nil; + _outputStream.delegate = nil; + + // Remove the streams, right now, from the networkRunLoop + [_inputStream close]; + [_outputStream close]; + } + + // Cleanup selfRetain in the same GCD queue as usual + dispatch_async(_workQueue, ^{ + _selfRetain = nil; + }); +} + + +static const char CRLFCRLFBytes[] = {'\r', '\n', '\r', '\n'}; + +- (void)_readUntilHeaderCompleteWithCallback:(data_callback)dataHandler; +{ + [self _readUntilBytes:CRLFCRLFBytes length:sizeof(CRLFCRLFBytes) callback:dataHandler]; +} + +- (void)_readUntilBytes:(const void *)bytes length:(size_t)length callback:(data_callback)dataHandler; +{ + // TODO optimize so this can continue from where we last searched + stream_scanner consumer = ^size_t(NSData *data) { + __block size_t found_size = 0; + __block size_t match_count = 0; + + size_t size = data.length; + const unsigned char *buffer = data.bytes; + for (size_t i = 0; i < size; i++ ) { + if (((const unsigned char *)buffer)[i] == ((const unsigned char *)bytes)[match_count]) { + match_count += 1; + if (match_count == length) { + found_size = i + 1; + break; + } + } else { + match_count = 0; + } + } + return found_size; + }; + [self _addConsumerWithScanner:consumer callback:dataHandler]; +} + + +// Returns true if did work +- (BOOL)_innerPumpScanner { + + BOOL didWork = NO; + + if (self.readyState >= SR_CLOSED) { + return didWork; + } + + size_t readBufferSize = dispatch_data_get_size(_readBuffer); + + if (!_consumers.count) { + return didWork; + } + + size_t curSize = readBufferSize - _readBufferOffset; + if (!curSize) { + return didWork; + } + + SRIOConsumer *consumer = [_consumers objectAtIndex:0]; + + size_t bytesNeeded = consumer.bytesNeeded; + + size_t foundSize = 0; + if (consumer.consumer) { + NSData *subdata = (NSData *)dispatch_data_create_subrange(_readBuffer, _readBufferOffset, readBufferSize - _readBufferOffset); + foundSize = consumer.consumer(subdata); + } else { + assert(consumer.bytesNeeded); + if (curSize >= bytesNeeded) { + foundSize = bytesNeeded; + } else if (consumer.readToCurrentFrame) { + foundSize = curSize; + } + } + + if (consumer.readToCurrentFrame || foundSize) { + dispatch_data_t slice = dispatch_data_create_subrange(_readBuffer, _readBufferOffset, foundSize); + + _readBufferOffset += foundSize; + + if (_readBufferOffset > SRDefaultBufferSize() && _readBufferOffset > readBufferSize / 2) { + _readBuffer = dispatch_data_create_subrange(_readBuffer, _readBufferOffset, readBufferSize - _readBufferOffset); + _readBufferOffset = 0; + } + + if (consumer.unmaskBytes) { + __block NSMutableData *mutableSlice = [slice mutableCopy]; + + NSUInteger len = mutableSlice.length; + uint8_t *bytes = mutableSlice.mutableBytes; + + for (NSUInteger i = 0; i < len; i++) { + bytes[i] = bytes[i] ^ _currentReadMaskKey[_currentReadMaskOffset % sizeof(_currentReadMaskKey)]; + _currentReadMaskOffset += 1; + } + + slice = dispatch_data_create(bytes, len, nil, ^{ + mutableSlice = nil; + }); + } + + if (consumer.readToCurrentFrame) { + dispatch_data_apply(slice, ^bool(dispatch_data_t region, size_t offset, const void *buffer, size_t size) { + [_currentFrameData appendBytes:buffer length:size]; + return true; + }); + + _readOpCount += 1; + + if (_currentFrameOpcode == SROpCodeTextFrame) { + // Validate UTF8 stuff. + size_t currentDataSize = _currentFrameData.length; + if (_currentFrameOpcode == SROpCodeTextFrame && currentDataSize > 0) { + // TODO: Optimize the crap out of this. Don't really have to copy all the data each time + + size_t scanSize = currentDataSize - _currentStringScanPosition; + + NSData *scan_data = [_currentFrameData subdataWithRange:NSMakeRange(_currentStringScanPosition, scanSize)]; + int32_t valid_utf8_size = validate_dispatch_data_partial_string(scan_data); + + if (valid_utf8_size == -1) { + [self closeWithCode:SRStatusCodeInvalidUTF8 reason:@"Text frames must be valid UTF-8"]; + dispatch_async(_workQueue, ^{ + [self closeConnection]; + }); + return didWork; + } else { + _currentStringScanPosition += valid_utf8_size; + } + } + + } + + consumer.bytesNeeded -= foundSize; + + if (consumer.bytesNeeded == 0) { + [_consumers removeObjectAtIndex:0]; + consumer.handler(self, nil); + [_consumerPool returnConsumer:consumer]; + didWork = YES; + } + } else if (foundSize) { + [_consumers removeObjectAtIndex:0]; + consumer.handler(self, (NSData *)slice); + [_consumerPool returnConsumer:consumer]; + didWork = YES; + } + } + return didWork; +} + +-(void)_pumpScanner; +{ + [self assertOnWorkQueue]; + + if (!_isPumping) { + _isPumping = YES; + } else { + return; + } + + while ([self _innerPumpScanner]) { + + } + + _isPumping = NO; +} + +//#define NOMASK + +static const size_t SRFrameHeaderOverhead = 32; + +- (void)_sendFrameWithOpcode:(SROpCode)opCode data:(NSData *)data +{ + [self assertOnWorkQueue]; + + if (!data) { + return; + } + + size_t payloadLength = data.length; + + NSMutableData *frameData = [[NSMutableData alloc] initWithLength:payloadLength + SRFrameHeaderOverhead]; + if (!frameData) { + [self closeWithCode:SRStatusCodeMessageTooBig reason:@"Message too big"]; + return; + } + uint8_t *frameBuffer = (uint8_t *)frameData.mutableBytes; + + // set fin + frameBuffer[0] = SRFinMask | opCode; + + // set the mask and header + frameBuffer[1] |= SRMaskMask; + + size_t frameBufferSize = 2; + + if (payloadLength < 126) { + frameBuffer[1] |= payloadLength; + } else { + uint64_t declaredPayloadLength = 0; + size_t declaredPayloadLengthSize = 0; + + if (payloadLength <= UINT16_MAX) { + frameBuffer[1] |= 126; + + declaredPayloadLength = CFSwapInt16BigToHost((uint16_t)payloadLength); + declaredPayloadLengthSize = sizeof(uint16_t); + } else { + frameBuffer[1] |= 127; + + declaredPayloadLength = CFSwapInt64BigToHost((uint64_t)payloadLength); + declaredPayloadLengthSize = sizeof(uint64_t); + } + + memcpy((frameBuffer + frameBufferSize), &declaredPayloadLength, declaredPayloadLengthSize); + frameBufferSize += declaredPayloadLengthSize; + } + + const uint8_t *unmaskedPayloadBuffer = (uint8_t *)data.bytes; + uint8_t *maskKey = frameBuffer + frameBufferSize; + + size_t randomBytesSize = sizeof(uint32_t); + int result = SecRandomCopyBytes(kSecRandomDefault, randomBytesSize, maskKey); + if (result != 0) { + //TODO: (nlutsenko) Check if there was an error. + } + frameBufferSize += randomBytesSize; + + // Copy and unmask the buffer + uint8_t *frameBufferPayloadPointer = frameBuffer + frameBufferSize; + + memcpy(frameBufferPayloadPointer, unmaskedPayloadBuffer, payloadLength); + SRMaskBytesSIMD(frameBufferPayloadPointer, payloadLength, maskKey); + frameBufferSize += payloadLength; + + assert(frameBufferSize <= frameData.length); + frameData.length = frameBufferSize; + + [self _writeData:frameData]; +} + +- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode +{ + __weak typeof(self) wself = self; + + if (_requestRequiresSSL && !_streamSecurityValidated && + (eventCode == NSStreamEventHasBytesAvailable || eventCode == NSStreamEventHasSpaceAvailable)) { + SecTrustRef trust = (__bridge SecTrustRef)[aStream propertyForKey:(__bridge id)kCFStreamPropertySSLPeerTrust]; + if (trust) { + _streamSecurityValidated = [_securityPolicy evaluateServerTrust:trust forDomain:_urlRequest.URL.host]; + } + if (!_streamSecurityValidated) { + dispatch_async(_workQueue, ^{ + NSError *error = SRErrorWithDomainCodeDescription(NSURLErrorDomain, + NSURLErrorClientCertificateRejected, + @"Invalid server certificate."); + [wself _failWithError:error]; + }); + return; + } + dispatch_async(_workQueue, ^{ + [self didConnect]; + }); + } + dispatch_async(_workQueue, ^{ + [wself safeHandleEvent:eventCode stream:aStream]; + }); +} + +- (void)safeHandleEvent:(NSStreamEvent)eventCode stream:(NSStream *)aStream +{ + switch (eventCode) { + case NSStreamEventOpenCompleted: { + SRDebugLog(@"NSStreamEventOpenCompleted %@", aStream); + if (self.readyState >= SR_CLOSING) { + return; + } + assert(_readBuffer); + + if (!_requestRequiresSSL && self.readyState == SR_CONNECTING && aStream == _inputStream) { + [self didConnect]; + } + + [self _pumpWriting]; + [self _pumpScanner]; + + break; + } + + case NSStreamEventErrorOccurred: { + SRDebugLog(@"NSStreamEventErrorOccurred %@ %@", aStream, [[aStream streamError] copy]); + /// TODO specify error better! + [self _failWithError:aStream.streamError]; + _readBufferOffset = 0; + _readBuffer = dispatch_data_empty; + break; + + } + + case NSStreamEventEndEncountered: { + [self _pumpScanner]; + SRDebugLog(@"NSStreamEventEndEncountered %@", aStream); + if (aStream.streamError) { + [self _failWithError:aStream.streamError]; + } else { + dispatch_async(_workQueue, ^{ + if (self.readyState != SR_CLOSED) { + self.readyState = SR_CLOSED; + [self _scheduleCleanup]; + } + + if (!_sentClose && !_failed) { + _sentClose = YES; + // If we get closed in this state it's probably not clean because we should be sending this when we send messages + [self.delegateController performDelegateBlock:^(id _Nullable delegate, SRDelegateAvailableMethods availableMethods) { + if (availableMethods.didCloseWithCode) { + [delegate webSocket:self + didCloseWithCode:SRStatusCodeGoingAway + reason:@"Stream end encountered" + wasClean:NO]; + } + }]; + } + }); + } + + break; + } + + case NSStreamEventHasBytesAvailable: { + SRDebugLog(@"NSStreamEventHasBytesAvailable %@", aStream); + uint8_t buffer[SRDefaultBufferSize()]; + + while (_inputStream.hasBytesAvailable) { + NSInteger bytesRead = [_inputStream read:buffer maxLength:SRDefaultBufferSize()]; + if (bytesRead > 0) { + dispatch_data_t data = dispatch_data_create(buffer, bytesRead, nil, DISPATCH_DATA_DESTRUCTOR_DEFAULT); + if (!data) { + NSError *error = SRErrorWithCodeDescription(SRStatusCodeMessageTooBig, + @"Unable to allocate memory to read from socket."); + [self _failWithError:error]; + return; + } + _readBuffer = dispatch_data_create_concat(_readBuffer, data); + } else if (bytesRead == -1) { + [self _failWithError:_inputStream.streamError]; + } + } + [self _pumpScanner]; + break; + } + + case NSStreamEventHasSpaceAvailable: { + SRDebugLog(@"NSStreamEventHasSpaceAvailable %@", aStream); + [self _pumpWriting]; + break; + } + + case NSStreamEventNone: + SRDebugLog(@"(default) %@", aStream); + break; + } +} + +///-------------------------------------- +#pragma mark - Delegate +///-------------------------------------- + +- (id _Nullable)delegate +{ + return self.delegateController.delegate; +} + +- (void)setDelegate:(id _Nullable)delegate +{ + self.delegateController.delegate = delegate; +} + +- (void)setDelegateDispatchQueue:(dispatch_queue_t _Nullable)queue +{ + self.delegateController.dispatchQueue = queue; +} + +- (dispatch_queue_t _Nullable)delegateDispatchQueue +{ + return self.delegateController.dispatchQueue; +} + +- (void)setDelegateOperationQueue:(NSOperationQueue *_Nullable)queue +{ + self.delegateController.operationQueue = queue; +} + +- (NSOperationQueue *_Nullable)delegateOperationQueue +{ + return self.delegateController.operationQueue; +} + +@end + +#ifdef HAS_ICU + +static inline int32_t validate_dispatch_data_partial_string(NSData *data) { + if ([data length] > INT32_MAX) { + // INT32_MAX is the limit so long as this Framework is using 32 bit ints everywhere. + return -1; + } + + int32_t size = (int32_t)[data length]; + + const void * contents = [data bytes]; + const uint8_t *str = (const uint8_t *)contents; + + UChar32 codepoint = 1; + int32_t offset = 0; + int32_t lastOffset = 0; + while(offset < size && codepoint > 0) { + lastOffset = offset; + U8_NEXT(str, offset, size, codepoint); + } + + 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; +} + +#else + +// 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; +} + +#endif diff --git a/Sources/Vendor/SocketRocket/SocketRocket/SocketRocket.h b/Sources/Vendor/SocketRocket/SocketRocket/SocketRocket.h new file mode 100755 index 0000000..c7ab062 --- /dev/null +++ b/Sources/Vendor/SocketRocket/SocketRocket/SocketRocket.h @@ -0,0 +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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import +#import +#import +#import diff --git a/Sources/Vendor/SocketRocket/TestChat/TCAppDelegate.h b/Sources/Vendor/SocketRocket/TestChat/TCAppDelegate.h new file mode 100755 index 0000000..040664d --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChat/TCAppDelegate.h @@ -0,0 +1,16 @@ +// +// Copyright 2012 Square Inc. +// Portions Copyright (c) 2016-present, Facebook, Inc. +// All rights reserved. +// +// This source code is licensed under the license found in the +// LICENSE-examples file in the root directory of this source tree. +// + +#import + +@interface TCAppDelegate : UIResponder + +@property (nonatomic, strong) UIWindow *window; + +@end diff --git a/Sources/Vendor/SocketRocket/TestChat/TCAppDelegate.m b/Sources/Vendor/SocketRocket/TestChat/TCAppDelegate.m new file mode 100755 index 0000000..7170a1e --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChat/TCAppDelegate.m @@ -0,0 +1,19 @@ +// +// Copyright 2012 Square Inc. +// Portions Copyright (c) 2016-present, Facebook, Inc. +// All rights reserved. +// +// This source code is licensed under the license found in the +// LICENSE-examples file in the root directory of this source tree. +// + +#import "TCAppDelegate.h" + +@implementation TCAppDelegate + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + return YES; +} + +@end diff --git a/Sources/Vendor/SocketRocket/TestChat/TCChatCell.h b/Sources/Vendor/SocketRocket/TestChat/TCChatCell.h new file mode 100755 index 0000000..7aa5a59 --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChat/TCChatCell.h @@ -0,0 +1,17 @@ +// +// Copyright 2012 Square Inc. +// Portions Copyright (c) 2016-present, Facebook, Inc. +// All rights reserved. +// +// This source code is licensed under the license found in the +// LICENSE-examples file in the root directory of this source tree. +// + +#import + +@interface TCChatCell : UITableViewCell + +@property (nonatomic, retain) IBOutlet UITextView *textView; +@property (nonatomic, retain) IBOutlet UILabel *nameLabel; + +@end diff --git a/Sources/Vendor/SocketRocket/TestChat/TCChatCell.m b/Sources/Vendor/SocketRocket/TestChat/TCChatCell.m new file mode 100755 index 0000000..29437d4 --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChat/TCChatCell.m @@ -0,0 +1,40 @@ +// +// Copyright 2012 Square Inc. +// Portions Copyright (c) 2016-present, Facebook, Inc. +// All rights reserved. +// +// This source code is licensed under the license found in the +// LICENSE-examples file in the root directory of this source tree. +// + +#import "TCChatCell.h" + +@implementation TCChatCell + +@synthesize nameLabel = _nameLabel; +@synthesize textView = _textView; + +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier +{ + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; + if (self) { + // Initialization code + } + return self; +} + +- (CGSize)sizeThatFits:(CGSize)size; +{ + CGSize textViewSize = _textView.bounds.size; + CGSize fitTextViewSize = CGSizeMake(textViewSize.width, size.height); + CGSize sizeThatFitsSize = [self.textView sizeThatFits:fitTextViewSize]; + + CGSize superSize = [super sizeThatFits:size]; + + sizeThatFitsSize.height = MAX(superSize.height, sizeThatFitsSize.height); + sizeThatFitsSize.width = superSize.width; + + return sizeThatFitsSize; +} + +@end diff --git a/Sources/Vendor/SocketRocket/TestChat/TCViewController.h b/Sources/Vendor/SocketRocket/TestChat/TCViewController.h new file mode 100755 index 0000000..f94cdf3 --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChat/TCViewController.h @@ -0,0 +1,19 @@ +// +// Copyright 2012 Square Inc. +// Portions Copyright (c) 2016-present, Facebook, Inc. +// All rights reserved. +// +// This source code is licensed under the license found in the +// LICENSE-examples file in the root directory of this source tree. +// + +#import + +@interface TCViewController : UITableViewController + +@property (nonatomic, strong) IBOutlet UITextView *inputView; + +- (IBAction)reconnect:(id)sender; +- (IBAction)sendPing:(id)sender; + +@end diff --git a/Sources/Vendor/SocketRocket/TestChat/TCViewController.m b/Sources/Vendor/SocketRocket/TestChat/TCViewController.m new file mode 100755 index 0000000..c68854e --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChat/TCViewController.m @@ -0,0 +1,195 @@ +// +// Copyright 2012 Square Inc. +// Portions Copyright (c) 2016-present, Facebook, Inc. +// All rights reserved. +// +// This source code is licensed under the license found in the +// LICENSE-examples file in the root directory of this source tree. +// + +#import "TCViewController.h" + +#import + +#import "TCChatCell.h" + +@interface TCMessage : NSObject + +- (instancetype)initWithMessage:(NSString *)message incoming:(BOOL)incoming; + +@property (nonatomic, copy, readonly) NSString *message; +@property (nonatomic, assign, readonly, getter=isIncoming) BOOL incoming; + +@end + +@implementation TCMessage + +- (instancetype)initWithMessage:(NSString *)message incoming:(BOOL)incoming +{ + self = [super init]; + if (!self) return self; + + _incoming = incoming; + _message = message; + + return self; +} + +@end + + +@interface TCViewController () +{ + SRWebSocket *_webSocket; + NSMutableArray *_messages; +} + +@end + +@implementation TCViewController + +///-------------------------------------- +#pragma mark - View +///-------------------------------------- + +- (void)viewDidLoad; +{ + [super viewDidLoad]; + + _messages = [[NSMutableArray alloc] init]; +} + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + + [self reconnect:nil]; +} + +- (void)viewDidAppear:(BOOL)animated +{ + [super viewDidAppear:animated]; + + [_inputView becomeFirstResponder]; +} + +- (void)viewDidDisappear:(BOOL)animated +{ + [super viewDidDisappear:animated]; + + [_webSocket close]; + _webSocket = nil; +} + +///-------------------------------------- +#pragma mark - Actions +///-------------------------------------- + +- (IBAction)reconnect:(id)sender +{ + _webSocket.delegate = nil; + [_webSocket close]; + + _webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:@"wss://echo.websocket.org"]]; + _webSocket.delegate = self; + + self.title = @"Opening Connection..."; + [_webSocket open]; +} + +- (void)sendPing:(id)sender; +{ + [_webSocket sendPing:nil error:NULL]; +} + +///-------------------------------------- +#pragma mark - Messages +///-------------------------------------- + +- (void)_addMessage:(TCMessage *)message +{ + [_messages addObject:message]; + [self.tableView insertRowsAtIndexPaths:@[ [NSIndexPath indexPathForRow:_messages.count - 1 inSection:0] ] + withRowAnimation:UITableViewRowAnimationNone]; + [self.tableView scrollRectToVisible:self.tableView.tableFooterView.frame animated:YES]; +} + +///-------------------------------------- +#pragma mark - UITableViewController +///-------------------------------------- + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return _messages.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + TCMessage *message = _messages[indexPath.row]; + + TCChatCell *cell = [self.tableView dequeueReusableCellWithIdentifier:message.incoming ? @"ReceivedCell" : @"SentCell" + forIndexPath:indexPath]; + + cell.textView.text = message.message; + cell.nameLabel.text = message.incoming ? @"Other" : @"Me"; + + return cell; +} + +///-------------------------------------- +#pragma mark - SRWebSocketDelegate +///-------------------------------------- + +- (void)webSocketDidOpen:(SRWebSocket *)webSocket; +{ + NSLog(@"Websocket Connected"); + self.title = @"Connected!"; +} + +- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error; +{ + NSLog(@":( Websocket Failed With Error %@", error); + + self.title = @"Connection Failed! (see logs)"; + _webSocket = nil; +} + +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithString:(nonnull NSString *)string +{ + NSLog(@"Received \"%@\"", string); + [self _addMessage:[[TCMessage alloc] initWithMessage:string incoming:YES]]; +} + +- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean; +{ + NSLog(@"WebSocket closed"); + self.title = @"Connection Closed! (see logs)"; + _webSocket = nil; +} + +- (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload; +{ + NSLog(@"WebSocket received pong"); +} + +///-------------------------------------- +#pragma mark - UITextViewDelegate +///-------------------------------------- + +- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text +{ + if ([text rangeOfString:@"\n"].location != NSNotFound) { + NSString *message = [textView.text stringByReplacingCharactersInRange:range withString:text]; + message = [message stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + [_webSocket sendString:message error:NULL]; + + [self _addMessage:[[TCMessage alloc] initWithMessage:message incoming:NO]]; + + textView.text = nil; + return NO; + } + return YES; +} + +@end diff --git a/Sources/Vendor/SocketRocket/TestChat/TestChat-Info.plist b/Sources/Vendor/SocketRocket/TestChat/TestChat-Info.plist new file mode 100755 index 0000000..41b47ba --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChat/TestChat-Info.plist @@ -0,0 +1,42 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFiles + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIMainStoryboardFile + MainStoryboard + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/Sources/Vendor/SocketRocket/TestChat/en.lproj/Default-568h@2x.png b/Sources/Vendor/SocketRocket/TestChat/en.lproj/Default-568h@2x.png new file mode 100755 index 0000000..0891b7a Binary files /dev/null and b/Sources/Vendor/SocketRocket/TestChat/en.lproj/Default-568h@2x.png differ diff --git a/Sources/Vendor/SocketRocket/TestChat/en.lproj/InfoPlist.strings b/Sources/Vendor/SocketRocket/TestChat/en.lproj/InfoPlist.strings new file mode 100755 index 0000000..477b28f --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChat/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/Sources/Vendor/SocketRocket/TestChat/en.lproj/MainStoryboard.storyboard b/Sources/Vendor/SocketRocket/TestChat/en.lproj/MainStoryboard.storyboard new file mode 100755 index 0000000..9c0200b --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChat/en.lproj/MainStoryboard.storyboard @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources/Vendor/SocketRocket/TestChat/main.m b/Sources/Vendor/SocketRocket/TestChat/main.m new file mode 100755 index 0000000..5530600 --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChat/main.m @@ -0,0 +1,19 @@ +// +// Copyright 2012 Square Inc. +// Portions Copyright (c) 2016-present, Facebook, Inc. +// All rights reserved. +// +// This source code is licensed under the license found in the +// LICENSE-examples file in the root directory of this source tree. +// + +#import + +#import "TCAppDelegate.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([TCAppDelegate class])); + } +} diff --git a/Sources/Vendor/SocketRocket/TestChatServer/go/README b/Sources/Vendor/SocketRocket/TestChatServer/go/README new file mode 100755 index 0000000..6083b3c --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChatServer/go/README @@ -0,0 +1,3 @@ +With the latest weekly go: + + go run chatroom.go diff --git a/Sources/Vendor/SocketRocket/TestChatServer/go/chatroom.go b/Sources/Vendor/SocketRocket/TestChatServer/go/chatroom.go new file mode 100755 index 0000000..bc3a9c6 --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChatServer/go/chatroom.go @@ -0,0 +1,70 @@ +// +// Copyright 2012 Square Inc. +// Portions Copyright (c) 2016-present, Facebook, Inc. +// All rights reserved. +// +// This source code is licensed under the license found in the +// LICENSE-examples file in the root directory of this source tree. +// + +package main + +import ( + "code.google.com/p/go.net/websocket" + "net/http" +) + +// Msg stores both the message and the connection +type Msg struct { + sender *websocket.Conn + msg string +} + +func run(reg chan *websocket.Conn, unreg chan *websocket.Conn, msg chan Msg) { + conns := make(map[*websocket.Conn]int) + for { + select { + case c := <-reg: + conns[c] = 1 + case c := <-unreg: + delete(conns, c) + case msg := <-msg: + for c := range conns { + if c != msg.sender { + websocket.Message.Send(c, msg.msg) + } + } + } + } +} + +func newChatServer(reg chan *websocket.Conn, unreg chan *websocket.Conn, msg chan Msg) websocket.Handler { + return func(ws *websocket.Conn) { + reg <- ws + for { + var message string + err := websocket.Message.Receive(ws, &message) + if err != nil { + unreg <- ws + break + } + msg <- Msg{ws, message} + } + } +} + +func main() { + reg := make(chan *websocket.Conn) + unreg := make(chan *websocket.Conn) + msg := make(chan Msg) + + http.Handle("/chat", websocket.Handler(newChatServer(reg, unreg, msg))) + http.Handle("/", http.FileServer(http.Dir("../static"))) + + go run(reg, unreg, msg) + + err := http.ListenAndServe(":9000", nil) + if err != nil { + panic("ListenAndServe: " + err.Error()) + } +} diff --git a/Sources/Vendor/SocketRocket/TestChatServer/py/chatroom.py b/Sources/Vendor/SocketRocket/TestChatServer/py/chatroom.py new file mode 100755 index 0000000..b304726 --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChatServer/py/chatroom.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# +# Copyright 2012 Square Inc. +# Portions Copyright (c) 2016-present, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the license found in the +# LICENSE-examples file in the root directory of this source tree. +# + +import tornado +import tornado.web +import tornado.websocket +import tornado.options + +import os + +import json +import uuid + +import argparse + +import logging + +logger = logging.getLogger('gateway') + +args = None + +def parse_args(): + global args + static_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'static')) + parser = argparse.ArgumentParser(description='Gateway server') + + parser.add_argument('-v', '--verbose', help='verbose logging', action='store_true') + + parser.add_argument('-s', '--static-path', help='path for static files [default: %(default)s]', default=static_path) + + parser.add_argument('-p', '--listen-port', help='port to listen on [default: %(default)s]', default=9000, type=int, metavar='PORT') + parser.add_argument('-i', '--listen-interface', help='interface to listen on. [default: %(default)s]', default='0.0.0.0', metavar='IFACE') + + args = parser.parse_args() + + +connections = set() + +class ChatHandler(tornado.websocket.WebSocketHandler): + def open(self): + connections.add(self) + return None + + def on_message(self, msg): + for c in connections: + if c is self: + continue + c.write_message(msg) + + def on_close(self): + connections.remove(self) + + +def main(): + global logger + #tornado.options.parse_command_line() + + parse_args() + + if args.verbose: + tornado.options.enable_pretty_logging() + logger = logging.getLogger() + logger.setLevel(logging.INFO) + + + application = tornado.web.Application([ + (r"/chat", ChatHandler), + (r"/(.*)", tornado.web.StaticFileHandler, {"path": args.static_path, "default_filename":'index.html'}), + ], + ) + + + print "Listening on %s:%s" % (args.listen_interface, args.listen_port) + application.listen(args.listen_port, args.listen_interface) + tornado.ioloop.IOLoop.instance().start() + + +if __name__ == "__main__": + main() diff --git a/Sources/Vendor/SocketRocket/TestChatServer/static/.gitignore b/Sources/Vendor/SocketRocket/TestChatServer/static/.gitignore new file mode 100755 index 0000000..91dc206 --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChatServer/static/.gitignore @@ -0,0 +1 @@ +devtools/ diff --git a/Sources/Vendor/SocketRocket/TestChatServer/static/index.html b/Sources/Vendor/SocketRocket/TestChatServer/static/index.html new file mode 100755 index 0000000..bd0692a --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChatServer/static/index.html @@ -0,0 +1,38 @@ + + + + + + + +

Chat History

+
    +
+
+ + +
+ +
    +
    + + diff --git a/Sources/Vendor/SocketRocket/TestChatServer/static/proxy.js b/Sources/Vendor/SocketRocket/TestChatServer/static/proxy.js new file mode 100755 index 0000000..fc89382 --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestChatServer/static/proxy.js @@ -0,0 +1,81 @@ +// +// Copyright 2012 Square Inc. +// Portions Copyright (c) 2016-present, Facebook, Inc. +// All rights reserved. +// +// This source code is licensed under the license found in the +// LICENSE-examples file in the root directory of this source tree. +// + +function SocketClient () { + this.list_elem = document.getElementById('client_list'); + this.info_div = document.getElementById('info_div'); + var self = this; +} + +SocketClient.prototype.connect = function () { + var self = this; + + this.list_elem.innerHTML = ''; + this.info_div.innerHTML = 'status: connecting...'; + this.socket = new WebSocket("ws://" + document.location.host + "/chat"); + + this.socket.onopen = function () {self.onopen.apply(self, arguments);}; + this.socket.onmessage = function () {self.onmessage.apply(self, arguments);}; + this.socket.onclose = function () {self.onclose.apply(self, arguments);}; +}; + +SocketClient.prototype.deviceAdded = function (params) { + var el = document.createElement('li'); + el.innerHTML = '' + params.device_name + '' + ' (' + params.app_id + ', ' + params.device_model + ', ' + params.device_id + ')'; + this.list_elem.appendChild(el); + this.visibleElems[params.connection_id] = el; +}; + +SocketClient.prototype.deviceRemoved = function (params) { + var li = this.visibleElems[params.connection_id]; + li.parentNode.removeChild(li); +}; + +SocketClient.prototype.onopen = function () { + this.info_div.innerHTML = 'status: connected to gateway'; + this.list_elem.innerHTML = ''; + this.visibleElems = {}; + console.log('connection to gateway opened'); +}; + +SocketClient.prototype.onmessage = function (message) { + var el = document.createElement('li'); + el.innerHTML = message.data; + window.document.getElementById('history').appendChild(el); +}; + +SocketClient.prototype.onclose = function () { + var retryInterval = 1000.0; + console.log('connection closed, retrying in ' + (retryInterval/1000.0) + ' seconds'); + var self = this; + window.setTimeout(function () {self.connect();}, retryInterval); +}; + + +window.addEventListener('load', function () { + var form = window.document.getElementById('msg_form'); + var msg_field = window.document.getElementById('msg_field'); + + var socketClient = new SocketClient(); + socketClient.connect() + + form.onsubmit = function () { + msg = msg_field.value; + msg_field.value = ''; + + socketClient.socket.send(msg); + + var el = document.createElement('li'); + el.innerHTML = msg; + window.document.getElementById('history').appendChild(el); + + return false; + }; + } +); diff --git a/Sources/Vendor/SocketRocket/TestSupport/autobahn_fuzzingserver.json b/Sources/Vendor/SocketRocket/TestSupport/autobahn_fuzzingserver.json new file mode 100755 index 0000000..6bfc651 --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestSupport/autobahn_fuzzingserver.json @@ -0,0 +1,7 @@ +{ + "url": "ws://127.0.0.1:9001", + "outdir": "./pages/results", + "cases": ["*"], + "exclude-cases": [], + "exclude-agent-cases": {} +} diff --git a/Sources/Vendor/SocketRocket/TestSupport/run_test_server.sh b/Sources/Vendor/SocketRocket/TestSupport/run_test_server.sh new file mode 100755 index 0000000..bd0265c --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestSupport/run_test_server.sh @@ -0,0 +1,18 @@ +# +# Copyright (c) 2016-present, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the license found in the +# LICENSE-examples file in the root directory of this source tree. +# + +PYENV_PATH=$(pwd)/.env + +echo $PYENV_PATH +if [ -d "$PYENV_PATH" ]; then + source $PYENV_PATH/bin/activate + $PYENV_PATH/bin/wstest -m fuzzingserver -s TestSupport/autobahn_fuzzingserver.json +else + echo "Python Virtualenv not set up. Please run './TestSupport/setup_env.sh .env' first." +fi + diff --git a/Sources/Vendor/SocketRocket/TestSupport/setup_env.sh b/Sources/Vendor/SocketRocket/TestSupport/setup_env.sh new file mode 100755 index 0000000..f34f8cd --- /dev/null +++ b/Sources/Vendor/SocketRocket/TestSupport/setup_env.sh @@ -0,0 +1,36 @@ +# +# Copyright (c) 2016-present, Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the license found in the +# LICENSE-examples file in the root directory of this source tree. +# + +VIRTUALENV_PATH=$1 +VIRTUALENV_VERSION=15.0.1 + +if [ -d "$VIRTUALENV_PATH" ]; then + echo "Virtual Env already installed" +elif [ -z "$VIRTUALENV_PATH" ]; then + echo "Usage: ./setup_env.sh " +else + mkdir $VIRTUALENV_PATH + + pushd $VIRTUALENV_PATH + + curl -L -o virtualenv.tar.gz https://pypi.python.org/packages/source/v/virtualenv/virtualenv-$VIRTUALENV_VERSION.tar.gz + tar xvfz virtualenv.tar.gz + + pushd virtualenv-$VIRTUALENV_VERSION + python setup.py install --user + popd + + popd + + python $VIRTUALENV_PATH/virtualenv-$VIRTUALENV_VERSION/virtualenv.py $VIRTUALENV_PATH + + source $VIRTUALENV_PATH/bin/activate + pip install autobahntestsuite + + echo "Environment succesfully set up in $VIRTUALENV_PATH." +fi diff --git a/Sources/Vendor/SocketRocket/Tests/Operations/SRAutobahnOperation.h b/Sources/Vendor/SocketRocket/Tests/Operations/SRAutobahnOperation.h new file mode 100755 index 0000000..09d956d --- /dev/null +++ b/Sources/Vendor/SocketRocket/Tests/Operations/SRAutobahnOperation.h @@ -0,0 +1,41 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRTWebSocketOperation.h" + +NS_ASSUME_NONNULL_BEGIN + +typedef void(^SRAutobahnSocketTextMessageHandler)(SRWebSocket *socket, NSString * _Nullable message); +typedef void(^SRAutobahnSocketDataMessageHandler)(SRWebSocket *socket, NSData * _Nullable message); + +@interface SRAutobahnOperation : SRTWebSocketOperation + +- (instancetype)initWithServerURL:(NSURL *)url + testCommandPath:(NSString *)path + caseNumber:(nullable NSNumber *)caseNumber + agent:(nullable NSString *)agent + textMessageHandler:(nullable SRAutobahnSocketTextMessageHandler)textMessageHandler + dataMessageHandler:(nullable SRAutobahnSocketDataMessageHandler)dataMessageHandler; + +@end + +extern SRAutobahnOperation *SRAutobahnTestOperation(NSURL *serverURL, NSInteger caseNumber, NSString *agent); + +typedef void(^SRAutobahnTestResultHandler)(NSDictionary *_Nullable result); +extern SRAutobahnOperation *SRAutobahnTestResultOperation(NSURL *serverURL, NSInteger caseNumber, NSString *agent, SRAutobahnTestResultHandler handler); + +typedef void(^SRAutobahnTestCaseInfoHandler)(NSDictionary *_Nullable caseInfo); +extern SRAutobahnOperation *SRAutobahnTestCaseInfoOperation(NSURL *serverURL, NSInteger caseNumber, SRAutobahnTestCaseInfoHandler handler); + +typedef void(^SRAutobahnTestCaseCountHandler)(NSInteger caseCount); +extern SRAutobahnOperation *SRAutobahnTestCaseCountOperation(NSURL *serverURL, NSString *agent, SRAutobahnTestCaseCountHandler handler); + +extern SRAutobahnOperation *SRAutobahnTestUpdateReportsOperation(NSURL *serverURL, NSString *agent); + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/Tests/Operations/SRAutobahnOperation.m b/Sources/Vendor/SocketRocket/Tests/Operations/SRAutobahnOperation.m new file mode 100755 index 0000000..96871f8 --- /dev/null +++ b/Sources/Vendor/SocketRocket/Tests/Operations/SRAutobahnOperation.m @@ -0,0 +1,131 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRAutobahnOperation.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SRAutobahnOperation () + +@property (nullable, nonatomic, copy, readonly) SRAutobahnSocketTextMessageHandler textMessageHandler; +@property (nullable, nonatomic, copy, readonly) SRAutobahnSocketDataMessageHandler dataMessageHandler; + +@end + +@implementation SRAutobahnOperation + +- (instancetype)initWithServerURL:(NSURL *)url + testCommandPath:(NSString *)path + caseNumber:(nullable NSNumber *)caseNumber + agent:(nullable NSString *)agent + textMessageHandler:(nullable SRAutobahnSocketTextMessageHandler)textMessageHandler + dataMessageHandler:(nullable SRAutobahnSocketDataMessageHandler)dataMessageHandler +{ + NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; + components.path = (components.path ? [components.path stringByAppendingPathComponent:path] : path); + + NSMutableArray *queryItems = [NSMutableArray arrayWithCapacity:2]; + if (caseNumber) { + [queryItems addObject:[NSURLQueryItem queryItemWithName:@"case" value:caseNumber.stringValue]]; + } + if (agent) { + [queryItems addObject:[NSURLQueryItem queryItemWithName:@"agent" value:agent]]; + } + components.queryItems = queryItems; + self = [self initWithURL:components.URL]; + if (!self) return self; + + _textMessageHandler = [textMessageHandler copy]; + _dataMessageHandler = [dataMessageHandler copy]; + + return self; +} + +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithString:(NSString *)string +{ + if (self.textMessageHandler) { + self.textMessageHandler(webSocket, string); + } +} + +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessageWithData:(NSData *)data +{ + if (self.dataMessageHandler) { + self.dataMessageHandler(webSocket, data); + } +} + +@end + +SRAutobahnOperation *SRAutobahnTestOperation(NSURL *serverURL, NSInteger caseNumber, NSString *agent) +{ + return [[SRAutobahnOperation alloc] initWithServerURL:serverURL + testCommandPath:@"/runCase" + caseNumber:@(caseNumber) + agent:agent + textMessageHandler:^(SRWebSocket * _Nonnull socket, NSString * _Nullable message) { + [socket sendString:message error:nil]; + } + dataMessageHandler:^(SRWebSocket * _Nonnull socket, NSData * _Nullable message) { + [socket sendData:message error:nil]; + }]; +} + +extern SRAutobahnOperation *SRAutobahnTestResultOperation(NSURL *serverURL, NSInteger caseNumber, NSString *agent, SRAutobahnTestResultHandler handler) +{ + return [[SRAutobahnOperation alloc] initWithServerURL:serverURL + testCommandPath:@"/getCaseStatus" + caseNumber:@(caseNumber) + agent:agent + textMessageHandler:^(SRWebSocket * _Nonnull socket, NSString * _Nullable message) { + NSData *messageData = [message dataUsingEncoding:NSUTF8StringEncoding]; + NSDictionary *result = [NSJSONSerialization JSONObjectWithData:messageData options:0 error:NULL]; + handler(result); + } + dataMessageHandler:nil]; +} + +extern SRAutobahnOperation *SRAutobahnTestCaseInfoOperation(NSURL *serverURL, NSInteger caseNumber, SRAutobahnTestCaseInfoHandler handler) +{ + return [[SRAutobahnOperation alloc] initWithServerURL:serverURL + testCommandPath:@"/getCaseInfo" + caseNumber:@(caseNumber) + agent:nil + textMessageHandler:^(SRWebSocket * _Nonnull socket, NSString * _Nullable message) { + NSData *messageData = [message dataUsingEncoding:NSUTF8StringEncoding]; + NSDictionary *result = [NSJSONSerialization JSONObjectWithData:messageData options:0 error:NULL]; + handler(result); + } + dataMessageHandler:nil]; +} + +extern SRAutobahnOperation *SRAutobahnTestCaseCountOperation(NSURL *serverURL, NSString *agent, SRAutobahnTestCaseCountHandler handler) +{ + return [[SRAutobahnOperation alloc] initWithServerURL:serverURL + testCommandPath:@"/getCaseCount" + caseNumber:nil + agent:agent + textMessageHandler:^(SRWebSocket * _Nonnull socket, NSString * _Nullable message) { + NSInteger count = [message integerValue]; + handler(count); + } + dataMessageHandler:nil]; +} + +extern SRAutobahnOperation *SRAutobahnTestUpdateReportsOperation(NSURL *serverURL, NSString *agent) +{ + return [[SRAutobahnOperation alloc] initWithServerURL:serverURL + testCommandPath:@"/updateReports" + caseNumber:nil + agent:agent + textMessageHandler:nil + dataMessageHandler:nil]; +} + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/Tests/Operations/SRTWebSocketOperation.h b/Sources/Vendor/SocketRocket/Tests/Operations/SRTWebSocketOperation.h new file mode 100755 index 0000000..c4d53c2 --- /dev/null +++ b/Sources/Vendor/SocketRocket/Tests/Operations/SRTWebSocketOperation.h @@ -0,0 +1,29 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import + +@interface SRTWebSocketOperation : NSOperation + +@property (nonatomic) BOOL isFinished; +@property (nonatomic) BOOL isExecuting; + +@property (nonatomic, strong, readonly) NSError *error; + +- (instancetype)initWithURL:(NSURL *)URL; + +// We override these methods. Please call super +- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean NS_REQUIRES_SUPER; +- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error NS_REQUIRES_SUPER; + +- (BOOL)waitUntilFinishedWithTimeout:(NSTimeInterval)timeout; + +@end diff --git a/Sources/Vendor/SocketRocket/Tests/Operations/SRTWebSocketOperation.m b/Sources/Vendor/SocketRocket/Tests/Operations/SRTWebSocketOperation.m new file mode 100755 index 0000000..27a2eb3 --- /dev/null +++ b/Sources/Vendor/SocketRocket/Tests/Operations/SRTWebSocketOperation.m @@ -0,0 +1,91 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRTWebSocketOperation.h" + +#import "SRAutobahnUtilities.h" + +@interface SRTWebSocketOperation () + +@end + +@implementation SRTWebSocketOperation { + NSInteger _testNumber; + SRWebSocket *_webSocket; + NSURL *_url; +} + +@synthesize isFinished = _isFinished; +@synthesize isExecuting = _isExecuting; +@synthesize error = _error; + +- (instancetype)initWithURL:(NSURL *)URL; +{ + self = [super init]; + if (self) { + _url = URL; + _isExecuting = NO; + _isFinished = NO; + } + return self; +} + +- (BOOL)isConcurrent; +{ + return YES; +} + +- (void)start; +{ + dispatch_async(dispatch_get_main_queue(), ^{ + _webSocket = [[SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:_url]]; + _webSocket.delegate = self; + [_webSocket open]; + }); + self.isExecuting = YES; +} + +- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean; +{ + [self willChangeValueForKey:@"isExecuting"]; + [self willChangeValueForKey:@"isFinished"]; + _isFinished = YES; + _isExecuting = NO; + [self didChangeValueForKey:@"isExecuting"]; + [self didChangeValueForKey:@"isFinished"]; + _webSocket.delegate = nil; + _webSocket = nil; +} + +- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error; +{ + _error = error; + [self willChangeValueForKey:@"isExecuting"]; + [self willChangeValueForKey:@"isFinished"]; + _isFinished = YES; + _isExecuting = NO; + [self didChangeValueForKey:@"isExecuting"]; + [self didChangeValueForKey:@"isFinished"]; + _webSocket.delegate = nil; + _webSocket = nil; +} + +- (BOOL)waitUntilFinishedWithTimeout:(NSTimeInterval)timeout +{ + if (self.isFinished) { + return YES; + } + return SRRunLoopRunUntil(^BOOL{ + return self.isFinished; + }, timeout); +} + +@end diff --git a/Sources/Vendor/SocketRocket/Tests/Resources/Info.plist b/Sources/Vendor/SocketRocket/Tests/Resources/Info.plist new file mode 100755 index 0000000..169b6f7 --- /dev/null +++ b/Sources/Vendor/SocketRocket/Tests/Resources/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/Sources/Vendor/SocketRocket/Tests/Resources/autobahn_configuration.json b/Sources/Vendor/SocketRocket/Tests/Resources/autobahn_configuration.json new file mode 100755 index 0000000..e5a1d9a --- /dev/null +++ b/Sources/Vendor/SocketRocket/Tests/Resources/autobahn_configuration.json @@ -0,0 +1,15 @@ +{ + "UNIMPLEMENTED": [ + "12", + "13" + ], + "NON-STRICT": [ + "6.4.2", + "6.4.4", + ], + "INFORMATIONAL": [ + "7.1.6", + "7.13.1", + "7.13.2" + ] +} \ No newline at end of file diff --git a/Sources/Vendor/SocketRocket/Tests/SRAutobahnTests.m b/Sources/Vendor/SocketRocket/Tests/SRAutobahnTests.m new file mode 100755 index 0000000..e752d25 --- /dev/null +++ b/Sources/Vendor/SocketRocket/Tests/SRAutobahnTests.m @@ -0,0 +1,146 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +@import XCTest; +@import ObjectiveC; + +#import + +#import "SRTWebSocketOperation.h" +#import "SRAutobahnOperation.h" +#import "SRAutobahnUtilities.h" + +@interface SRAutobahnTests : XCTestCase +@end + +@implementation SRAutobahnTests + +///-------------------------------------- +#pragma mark - Init +///-------------------------------------- + +/** + This method is called if Xcode is targeting a specific test or a set of them. + If you change this method - please make sure you test this behavior in Xcode by running all tests, then running 1+ test. + */ ++ (instancetype)testCaseWithSelector:(SEL)selector +{ + NSArray *invocations = [self testInvocations]; + for (NSInvocation *invocation in invocations) { + if (invocation.selector == selector) { + return [super testCaseWithSelector:selector]; + } + } + return nil; +} + +///-------------------------------------- +#pragma mark - Setup +///-------------------------------------- + +/** + This method is called by xctest to figure out all the tests that are available. + All the selector names are also reported back to Xcode and displayed in Test Navigator/Console. + */ ++ (NSArray *)testInvocations +{ + __block NSArray *array = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSMutableArray *invocations = [NSMutableArray array]; + for (NSUInteger i = 1; i <= SRAutobahnTestCaseCount(); i++) { + NSDictionary *caseInfo = SRAutobahnTestCaseInfo(i); + NSString *identifier = caseInfo[@"id"]; + + NSInvocation *invocation = [self invocationWithCaseNumber:i identifier:identifier]; + [invocations addObject:invocation]; + } + + array = [invocations sortedArrayUsingComparator:^NSComparisonResult(NSInvocation *_Nonnull obj1, NSInvocation *_Nonnull obj2) { + return [NSStringFromSelector(obj1.selector) compare:NSStringFromSelector(obj2.selector) options:NSNumericSearch]; + }]; + }); + return array; +} + ++ (NSInvocation *)invocationWithCaseNumber:(NSUInteger)caseNumber identifier:(NSString *)identifier +{ + SEL selector = [self addInstanceMethodForTestCaseNumber:caseNumber identifier:identifier]; + NSMethodSignature *signature = [self instanceMethodSignatureForSelector:selector]; + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; + invocation.selector = selector; + return invocation; +} + ++ (SEL)addInstanceMethodForTestCaseNumber:(NSInteger)caseNumber identifier:(NSString *)identifier +{ + NSString *selectorName = [NSString stringWithFormat:@"Case #%@", identifier]; + SEL selector = NSSelectorFromString(selectorName); + + IMP implementation = imp_implementationWithBlock(^(SRAutobahnTests *sself) { + [sself performTestWithCaseNumber:caseNumber identifier:identifier]; + }); + NSString *typeString = [NSString stringWithFormat:@"%s%s%s", @encode(id), @encode(id), @encode(SEL)]; + class_addMethod(self, selector, implementation, typeString.UTF8String); + + return selector; +} + +///-------------------------------------- +#pragma mark - Teardown +///-------------------------------------- + ++ (void)tearDown +{ + [self updateReports]; + [super tearDown]; +} + ++ (void)updateReports +{ + SRAutobahnOperation *operation = SRAutobahnTestUpdateReportsOperation(SRAutobahnTestServerURL(), SRAutobahnTestAgentName()); + [operation start]; + + NSAssert([operation waitUntilFinishedWithTimeout:60], @"Timed out on updating reports."); + NSAssert(!operation.error, @"Updating the report should not have errored %@", operation.error); +} + +///-------------------------------------- +#pragma mark - Test +///-------------------------------------- + +- (void)performTestWithCaseNumber:(NSInteger)caseNumber identifier:(NSString *)identifier +{ + NSURL *serverURL = SRAutobahnTestServerURL(); + NSString *agent = SRAutobahnTestAgentName(); + + NSOperationQueue *testQueue = [[NSOperationQueue alloc] init]; + testQueue.maxConcurrentOperationCount = 1; + + SRAutobahnOperation *testOp = SRAutobahnTestOperation(serverURL, caseNumber, agent); + [testQueue addOperation:testOp]; + + __block NSDictionary *resultInfo = nil; + SRAutobahnOperation *resultOp = SRAutobahnTestResultOperation(serverURL, caseNumber, agent, ^(NSDictionary * _Nullable result) { + resultInfo = result; + }); + [resultOp addDependency:testOp]; + [testQueue addOperation:resultOp]; + + + XCTAssertTrue([resultOp waitUntilFinishedWithTimeout:60 * 5], @"Test operation timed out."); + XCTAssertTrue(!testOp.error, @"Test operation should not have failed"); + if (!SRAutobahnIsValidResultBehavior(identifier, resultInfo[@"behavior"])) { + XCTFail(@"Invalid test behavior %@ for %@.", resultInfo[@"behavior"], identifier); + } +} + +@end diff --git a/Sources/Vendor/SocketRocket/Tests/Utilities/SRAutobahnUtilities.h b/Sources/Vendor/SocketRocket/Tests/Utilities/SRAutobahnUtilities.h new file mode 100755 index 0000000..4a5ff2f --- /dev/null +++ b/Sources/Vendor/SocketRocket/Tests/Utilities/SRAutobahnUtilities.h @@ -0,0 +1,41 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +@import Foundation; + +NS_ASSUME_NONNULL_BEGIN + +///-------------------------------------- +#pragma mark - Test Configuration +///-------------------------------------- + +extern NSString *SRAutobahnTestAgentName(void); +extern NSURL *SRAutobahnTestServerURL(void); + +///-------------------------------------- +#pragma mark - Validation +///-------------------------------------- + +extern NSDictionary *SRAutobahnTestConfiguration(void); +extern BOOL SRAutobahnIsValidResultBehavior(NSString *caseIdentifier, NSString *behavior); + +///-------------------------------------- +#pragma mark - Utilities +///-------------------------------------- + +extern BOOL SRRunLoopRunUntil(BOOL (^predicate)(), NSTimeInterval timeout); + +///-------------------------------------- +#pragma mark - Setup +///-------------------------------------- + +extern NSUInteger SRAutobahnTestCaseCount(void); +extern NSDictionary *SRAutobahnTestCaseInfo(NSInteger caseNumber); + +NS_ASSUME_NONNULL_END diff --git a/Sources/Vendor/SocketRocket/Tests/Utilities/SRAutobahnUtilities.m b/Sources/Vendor/SocketRocket/Tests/Utilities/SRAutobahnUtilities.m new file mode 100755 index 0000000..2ddcdf3 --- /dev/null +++ b/Sources/Vendor/SocketRocket/Tests/Utilities/SRAutobahnUtilities.m @@ -0,0 +1,120 @@ +// +// 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 +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import "SRAutobahnUtilities.h" + +#import "SRAutobahnOperation.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SRAutobahnUtilities : NSObject @end +@implementation SRAutobahnUtilities @end + +///-------------------------------------- +#pragma mark - Test Configuration +///-------------------------------------- + +NSString *SRAutobahnTestAgentName(void) +{ + return [NSBundle bundleForClass:[SRAutobahnUtilities class]].bundleIdentifier; +} + +NSURL *SRAutobahnTestServerURL(void) +{ + return [NSURL URLWithString:@"ws://localhost:9001"]; +} + +///-------------------------------------- +#pragma mark - Validation +///-------------------------------------- + +NSDictionary *SRAutobahnTestConfiguration(void) +{ + static NSDictionary *configuration; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSURL *configurationURL = [[NSBundle bundleForClass:[SRAutobahnUtilities class]] URLForResource:@"autobahn_configuration" + withExtension:@"json"]; + NSInputStream *readStream = [NSInputStream inputStreamWithURL:configurationURL]; + [readStream open]; + configuration = [NSJSONSerialization JSONObjectWithStream:readStream options:0 error:nil]; + [readStream close]; + }); + return configuration; +} + +BOOL SRAutobahnIsValidResultBehavior(NSString *caseIdentifier, NSString *behavior) +{ + if ([behavior isEqualToString:@"OK"]) { + return YES; + } + + NSArray *cases = SRAutobahnTestConfiguration()[behavior]; + for (NSString *caseId in cases) { + if ([caseIdentifier hasPrefix:caseId]) { + return YES; + } + } + return NO; +} + +///-------------------------------------- +#pragma mark - Utilities +///-------------------------------------- + +BOOL SRRunLoopRunUntil(BOOL (^predicate)(), NSTimeInterval timeout) +{ + NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:timeout]; + + NSTimeInterval timeoutTime = [timeoutDate timeIntervalSinceReferenceDate]; + NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate]; + + while (!predicate() && currentTime < timeoutTime) { + [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; + currentTime = [NSDate timeIntervalSinceReferenceDate]; + } + return (currentTime <= timeoutTime); +} + +///-------------------------------------- +#pragma mark - Setup +///-------------------------------------- + +NSUInteger SRAutobahnTestCaseCount(void) +{ + static NSUInteger count; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + SRAutobahnOperation *operation = SRAutobahnTestCaseCountOperation(SRAutobahnTestServerURL(), + SRAutobahnTestAgentName(), + ^(NSInteger caseCount) { + count = caseCount; + }); + [operation start]; + + NSCAssert([operation waitUntilFinishedWithTimeout:10], @"Timed out fetching test case count."); + NSCAssert(!operation.error, @"CaseGetter should have successfully returned the number of testCases. Instead got error %@", operation.error); + }); + return count; +} + +NSDictionary *SRAutobahnTestCaseInfo(NSInteger caseNumber) +{ + __block NSDictionary *caseInfo = nil; + SRAutobahnOperation *operation = SRAutobahnTestCaseInfoOperation(SRAutobahnTestServerURL(), caseNumber, ^(NSDictionary * _Nullable info) { + caseInfo = info; + }); + [operation start]; + + NSCAssert([operation waitUntilFinishedWithTimeout:10], @"Timed out fetching test case info %ld.", (long)caseNumber); + NSCAssert(!operation.error, @"Updating the report should not have errored"); + return caseInfo; +} + +NS_ASSUME_NONNULL_END diff --git a/Sources/com.elgato.applemail.sdPlugin/AppleMail b/Sources/com.elgato.applemail.sdPlugin/AppleMail new file mode 100755 index 0000000..91d4f39 Binary files /dev/null and b/Sources/com.elgato.applemail.sdPlugin/AppleMail differ diff --git a/Sources/com.elgato.applemail.sdPlugin/MailBadgeIcon.png b/Sources/com.elgato.applemail.sdPlugin/MailBadgeIcon.png new file mode 100644 index 0000000..f222856 Binary files /dev/null and b/Sources/com.elgato.applemail.sdPlugin/MailBadgeIcon.png differ diff --git a/Sources/com.elgato.applemail.sdPlugin/MailBadgeIcon@2x.png b/Sources/com.elgato.applemail.sdPlugin/MailBadgeIcon@2x.png new file mode 100644 index 0000000..b4e2854 Binary files /dev/null and b/Sources/com.elgato.applemail.sdPlugin/MailBadgeIcon@2x.png differ diff --git a/Sources/com.elgato.applemail.sdPlugin/MailIcon.png b/Sources/com.elgato.applemail.sdPlugin/MailIcon.png new file mode 100644 index 0000000..9c447df Binary files /dev/null and b/Sources/com.elgato.applemail.sdPlugin/MailIcon.png differ diff --git a/Sources/com.elgato.applemail.sdPlugin/MailIcon@2x.png b/Sources/com.elgato.applemail.sdPlugin/MailIcon@2x.png new file mode 100644 index 0000000..085d260 Binary files /dev/null and b/Sources/com.elgato.applemail.sdPlugin/MailIcon@2x.png differ diff --git a/Sources/com.elgato.applemail.sdPlugin/NumberOfUnreadMails.scpt b/Sources/com.elgato.applemail.sdPlugin/NumberOfUnreadMails.scpt new file mode 100644 index 0000000..3265e6a Binary files /dev/null and b/Sources/com.elgato.applemail.sdPlugin/NumberOfUnreadMails.scpt differ diff --git a/Sources/com.elgato.applemail.sdPlugin/OpenMail.scpt b/Sources/com.elgato.applemail.sdPlugin/OpenMail.scpt new file mode 100644 index 0000000..ed6d5c5 Binary files /dev/null and b/Sources/com.elgato.applemail.sdPlugin/OpenMail.scpt differ diff --git a/Sources/com.elgato.applemail.sdPlugin/de.json b/Sources/com.elgato.applemail.sdPlugin/de.json new file mode 100644 index 0000000..32ee8d8 --- /dev/null +++ b/Sources/com.elgato.applemail.sdPlugin/de.json @@ -0,0 +1,8 @@ +{ + "Description": "Zeigt die Anzahl ungelesener E-Mails von Apple Mail an.", + "Name": "Apple Mail", + "com.elgato.applemail.action": { + "Name": "Apple Mail", + "Tooltip": "Zeigt die Anzahl ungelesener E-Mails von Apple Mail an" + } +} \ No newline at end of file diff --git a/Sources/com.elgato.applemail.sdPlugin/en.json b/Sources/com.elgato.applemail.sdPlugin/en.json new file mode 100644 index 0000000..12227da --- /dev/null +++ b/Sources/com.elgato.applemail.sdPlugin/en.json @@ -0,0 +1,8 @@ +{ + "Description": "Display the number of unread emails from Apple Mail.", + "Name": "Apple Mail", + "com.elgato.applemail.action": { + "Name": "Apple Mail", + "Tooltip": "Display the number of unread emails from Apple Mail" + } +} \ No newline at end of file diff --git a/Sources/com.elgato.applemail.sdPlugin/es.json b/Sources/com.elgato.applemail.sdPlugin/es.json new file mode 100644 index 0000000..4527390 --- /dev/null +++ b/Sources/com.elgato.applemail.sdPlugin/es.json @@ -0,0 +1,8 @@ +{ + "Description": "Muestra el número de correos sin leer de la aplicación Mail de Apple.", + "Name": "Aplicación Mail de Apple", + "com.elgato.applemail.action": { + "Name": "Aplicación Mail de Apple", + "Tooltip": "Muestra el número de correos sin leer de la aplicación Mail de Apple" + } +} \ No newline at end of file diff --git a/Sources/com.elgato.applemail.sdPlugin/fr.json b/Sources/com.elgato.applemail.sdPlugin/fr.json new file mode 100644 index 0000000..9daddc1 --- /dev/null +++ b/Sources/com.elgato.applemail.sdPlugin/fr.json @@ -0,0 +1,8 @@ +{ + "Description": "Afficher le nombre d’e-mails non lus dans Apple Mail.", + "Name": "Apple Mail", + "com.elgato.applemail.action": { + "Name": "Apple Mail", + "Tooltip": "Afficher le nombre d’e-mails non lus dans Apple Mail" + } +} \ No newline at end of file diff --git a/Sources/com.elgato.applemail.sdPlugin/ja.json b/Sources/com.elgato.applemail.sdPlugin/ja.json new file mode 100644 index 0000000..ede9c37 --- /dev/null +++ b/Sources/com.elgato.applemail.sdPlugin/ja.json @@ -0,0 +1,8 @@ +{ + "Description": "Appleの“メール”の未開封のメール数を表示します。", + "Name": "Appleの“メール”", + "com.elgato.applemail.action": { + "Name": "Appleの“メール”", + "Tooltip": "Appleの“メール”の未開封のメール数を表示します" + } +} \ No newline at end of file diff --git a/Sources/com.elgato.applemail.sdPlugin/ko.json b/Sources/com.elgato.applemail.sdPlugin/ko.json new file mode 100644 index 0000000..4aa5e8f --- /dev/null +++ b/Sources/com.elgato.applemail.sdPlugin/ko.json @@ -0,0 +1,8 @@ +{ + "Description": "Apple Mail에서 읽지 않은 이메일 개수를 표시합니다.", + "Name": "Apple Mail", + "com.elgato.applemail.action": { + "Name": "Apple Mail", + "Tooltip": "Apple Mail에서 읽지 않은 이메일 개수를 표시합니다" + } +} \ No newline at end of file diff --git a/Sources/com.elgato.applemail.sdPlugin/manifest.json b/Sources/com.elgato.applemail.sdPlugin/manifest.json new file mode 100644 index 0000000..2889f4d --- /dev/null +++ b/Sources/com.elgato.applemail.sdPlugin/manifest.json @@ -0,0 +1,37 @@ +{ + "Actions": [ + { + "Icon": "MailIcon", + "Name": "Apple Mail", + "States": [ + { + "Image": "MailIcon", + "FontSize": "18", + "FontStyle": "Bold", + "TitleAlignment": "middle", + "TitleColor": "#ffffff" + } + ], + "Tooltip": "Display the number of unread emails from Apple Mail", + "UUID": "com.elgato.applemail.action" + } + ], + "Author": "Elgato", + "CodePath": "AppleMail", + "Description": "Display the number of unread emails from Apple Mail.", + "Name": "Apple Mail", + "Icon": "MailIcon", + "URL": "https://www.elgato.com/gaming/stream-deck", + "Version": "1.2", + "OS": [ + { + "Platform": "mac", + "MinimumVersion" : "10.11" + } + ], + "ApplicationsToMonitor": { + "mac": [ + "com.apple.mail" + ] + } +} diff --git a/Sources/com.elgato.applemail.sdPlugin/zh_CN.json b/Sources/com.elgato.applemail.sdPlugin/zh_CN.json new file mode 100644 index 0000000..dc908cc --- /dev/null +++ b/Sources/com.elgato.applemail.sdPlugin/zh_CN.json @@ -0,0 +1,8 @@ +{ + "Description": "显示 Apple“邮件”中未读电子邮件的数量。", + "Name": "Apple“邮件”", + "com.elgato.applemail.action": { + "Name": "Apple“邮件”", + "Tooltip": "显示 Apple“邮件”中未读电子邮件的数量" + } +} \ No newline at end of file