Showing preview only (327K chars total). Download the full file or copy to clipboard to get everything.
Repository: facebookincubator/SocketRocket
Branch: main
Commit: b7f833e3bf6b
Files: 96
Total size: 302.2 KB
Directory structure:
gitextract_2hs1q41a/
├── .gitignore
├── .gitmodules
├── .ruby-version
├── .travis.yml
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── Configurations/
│ ├── SocketRocket-iOS-Dynamic.xcconfig
│ ├── SocketRocket-iOS.xcconfig
│ ├── SocketRocket-macOS.xcconfig
│ ├── SocketRocket-tvOS.xcconfig
│ ├── SocketRocketTests-iOS.xcconfig
│ └── TestChat-iOS.xcconfig
├── Gemfile
├── LICENSE
├── LICENSE-examples
├── Makefile
├── PATENTS
├── README.md
├── SocketRocket/
│ ├── Internal/
│ │ ├── Delegate/
│ │ │ ├── SRDelegateController.h
│ │ │ └── SRDelegateController.m
│ │ ├── IOConsumer/
│ │ │ ├── SRIOConsumer.h
│ │ │ ├── SRIOConsumer.m
│ │ │ ├── SRIOConsumerPool.h
│ │ │ └── SRIOConsumerPool.m
│ │ ├── NSRunLoop+SRWebSocketPrivate.h
│ │ ├── NSURLRequest+SRWebSocketPrivate.h
│ │ ├── Proxy/
│ │ │ ├── SRProxyConnect.h
│ │ │ └── SRProxyConnect.m
│ │ ├── RunLoop/
│ │ │ ├── SRRunLoopThread.h
│ │ │ └── SRRunLoopThread.m
│ │ ├── SRConstants.h
│ │ ├── SRConstants.m
│ │ ├── Security/
│ │ │ ├── SRPinningSecurityPolicy.h
│ │ │ └── SRPinningSecurityPolicy.m
│ │ └── Utilities/
│ │ ├── SRError.h
│ │ ├── SRError.m
│ │ ├── SRHTTPConnectMessage.h
│ │ ├── SRHTTPConnectMessage.m
│ │ ├── SRHash.h
│ │ ├── SRHash.m
│ │ ├── SRLog.h
│ │ ├── SRLog.m
│ │ ├── SRMutex.h
│ │ ├── SRMutex.m
│ │ ├── SRRandom.h
│ │ ├── SRRandom.m
│ │ ├── SRSIMDHelpers.h
│ │ ├── SRSIMDHelpers.m
│ │ ├── SRURLUtilities.h
│ │ └── SRURLUtilities.m
│ ├── NSRunLoop+SRWebSocket.h
│ ├── NSRunLoop+SRWebSocket.m
│ ├── NSURLRequest+SRWebSocket.h
│ ├── NSURLRequest+SRWebSocket.m
│ ├── Resources/
│ │ └── Info.plist
│ ├── SRSecurityPolicy.h
│ ├── SRSecurityPolicy.m
│ ├── SRWebSocket.h
│ ├── SRWebSocket.m
│ └── SocketRocket.h
├── SocketRocket.podspec
├── SocketRocket.xcodeproj/
│ ├── project.pbxproj
│ └── xcshareddata/
│ └── xcschemes/
│ ├── SocketRocket-iOS-Dynamic.xcscheme
│ ├── SocketRocket-iOS.xcscheme
│ ├── SocketRocket-macOS.xcscheme
│ ├── SocketRocket-tvOS.xcscheme
│ ├── SocketRocketTests.xcscheme
│ └── TestChat.xcscheme
├── TestChat/
│ ├── TCAppDelegate.h
│ ├── TCAppDelegate.m
│ ├── TCChatCell.h
│ ├── TCChatCell.m
│ ├── TCViewController.h
│ ├── TCViewController.m
│ ├── TestChat-Info.plist
│ ├── en.lproj/
│ │ ├── InfoPlist.strings
│ │ └── MainStoryboard.storyboard
│ └── main.m
├── TestChatServer/
│ ├── go/
│ │ ├── README
│ │ └── chatroom.go
│ ├── py/
│ │ └── chatroom.py
│ └── static/
│ ├── .gitignore
│ ├── index.html
│ └── proxy.js
├── TestSupport/
│ ├── autobahn_fuzzingserver.json
│ ├── run_test_server.sh
│ └── setup_env.sh
└── Tests/
├── Operations/
│ ├── SRAutobahnOperation.h
│ ├── SRAutobahnOperation.m
│ ├── SRTWebSocketOperation.h
│ └── SRTWebSocketOperation.m
├── Resources/
│ ├── Info.plist
│ └── autobahn_configuration.json
├── SRAutobahnTests.m
└── Utilities/
├── SRAutobahnUtilities.h
└── SRAutobahnUtilities.m
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.idea/
.env/
*.egg-info
reports/
build/
nohup.out
.DS_Store
xcuserdata/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
!default.xcworkspace
*xcuserdata
*.xccheckout
profile
*.moved-aside
DerivedData
extern/
*.pyc
================================================
FILE: .gitmodules
================================================
[submodule "Vendor/xctoolchain"]
path = Vendor/xctoolchain
url = https://github.com/nlutsenko/xctoolchain.git
================================================
FILE: .ruby-version
================================================
2.3.1
================================================
FILE: .travis.yml
================================================
branches:
only:
- master
language: objective-c
os: osx
osx_image: xcode7.3
env:
matrix:
- TEST_TYPE=iOS
- TEST_TYPE=OSX
- TEST_TYPE=tvOS
- TEST_TYPE=CocoaPods
- TEST_TYPE=Carthage
before_install:
- |
if [ "$TEST_TYPE" = iOS ] || [ "$TEST_TYPE" = OSX ] || [ "$TEST_TYPE" = tvOS ]; then
bundle install
elif [ "$TEST_TYPE" = Carthage ]; then
brew update
brew install carthage || brew upgrade carthage
fi
install:
- |
if [ "$TEST_TYPE" = iOS ]; then
./TestSupport/setup_env.sh .env
fi
script:
- |
if [ "$TEST_TYPE" = iOS ]; then
set -o pipefail
xcodebuild -project SocketRocket.xcodeproj -scheme "SocketRocket-iOS" -sdk iphonesimulator build test
elif [ "$TEST_TYPE" = OSX ]; then
set -o pipefail
xcodebuild -project SocketRocket.xcodeproj -scheme "SocketRocket-macOS" -sdk macosx build | xcpretty -c
elif [ "$TEST_TYPE" = tvOS ]; then
set -o pipefail
xcodebuild -project SocketRocket.xcodeproj -scheme "SocketRocket-tvOS" -sdk appletvsimulator build | xcpretty -c
elif [ "$TEST_TYPE" = CocoaPods ]; then
pod lib lint SocketRocket.podspec
pod lib lint --use-libraries SocketRocket.podspec
elif [ "$TEST_TYPE" = Carthage ]; then
carthage build --no-skip-current
fi
================================================
FILE: CODE_OF_CONDUCT.md
================================================
# Code of Conduct
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://code.fb.com/codeofconduct) so that you can understand what actions will and will not be tolerated.
================================================
FILE: CONTRIBUTING.md
================================================
# 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: <https://code.facebook.com/cla>
## 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.
================================================
FILE: Configurations/SocketRocket-iOS-Dynamic.xcconfig
================================================
//
// 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 = 11.0
INFOPLIST_FILE = $(SRCROOT)/SocketRocket/Resources/Info.plist
================================================
FILE: Configurations/SocketRocket-iOS.xcconfig
================================================
//
// 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 = 11.0
INFOPLIST_FILE = $(SRCROOT)/SocketRocket/Resources/Info.plist
OTHER_CFLAGS[sdk=iphoneos9.*] = $(inherited) -fembed-bitcode
OTHER_LDFLAGS = $(inherited) -Licucore
================================================
FILE: Configurations/SocketRocket-macOS.xcconfig
================================================
//
// 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.13
INFOPLIST_FILE = $(SRCROOT)/SocketRocket/Resources/Info.plist
================================================
FILE: Configurations/SocketRocket-tvOS.xcconfig
================================================
//
// 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
TVOS_DEPLOYMENT_TARGET = 11.0
INFOPLIST_FILE = $(SRCROOT)/SocketRocket/Resources/Info.plist
================================================
FILE: Configurations/SocketRocketTests-iOS.xcconfig
================================================
//
// 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 = 11.0
INFOPLIST_FILE = $(SRCROOT)/Tests/Resources/Info.plist
================================================
FILE: Configurations/TestChat-iOS.xcconfig
================================================
//
// 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 = 11.0
INFOPLIST_FILE = $(SRCROOT)/TestChat/TestChat-Info.plist
================================================
FILE: Gemfile
================================================
source 'https://rubygems.org'
gem 'cocoapods'
gem 'xcpretty'
================================================
FILE: LICENSE
================================================
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.
================================================
FILE: LICENSE-examples
================================================
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.
================================================
FILE: Makefile
================================================
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
================================================
FILE: PATENTS
================================================
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.
================================================
FILE: README.md
================================================
# 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, tvOS and visionOS.
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 <SRWebSocketDelegate> 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 <NSObject>
@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 `SocketRocketTests` target
- Make sure your running destination is either your Mac or any Simulator
- 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
================================================
FILE: SocketRocket/Internal/Delegate/SRDelegateController.h
================================================
//
// 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/Foundation.h>
#import <SocketRocket/SRWebSocket.h>
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<SRWebSocketDelegate> _Nullable delegate, SRDelegateAvailableMethods availableMethods);
@interface SRDelegateController : NSObject
@property (nonatomic, weak) id<SRWebSocketDelegate> 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
================================================
FILE: SocketRocket/Internal/Delegate/SRDelegateController.m
================================================
//
// 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<SRWebSocketDelegate> _Nullable)delegate
{
dispatch_barrier_async(self.accessQueue, ^{
self->_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<SRWebSocketDelegate> _Nullable)delegate
{
__block id<SRWebSocketDelegate> delegate = nil;
dispatch_sync(self.accessQueue, ^{
delegate = self->_delegate;
});
return delegate;
}
- (void)setDispatchQueue:(dispatch_queue_t _Nullable)queue
{
dispatch_barrier_async(self.accessQueue, ^{
self->_dispatchQueue = queue ?: dispatch_get_main_queue();
self->_operationQueue = nil;
});
}
- (dispatch_queue_t _Nullable)dispatchQueue
{
__block dispatch_queue_t queue = nil;
dispatch_sync(self.accessQueue, ^{
queue = self->_dispatchQueue;
});
return queue;
}
- (void)setOperationQueue:(NSOperationQueue *_Nullable)queue
{
dispatch_barrier_async(self.accessQueue, ^{
self->_dispatchQueue = queue ? nil : dispatch_get_main_queue();
self->_operationQueue = queue;
});
}
- (NSOperationQueue *_Nullable)operationQueue
{
__block NSOperationQueue *queue = nil;
dispatch_sync(self.accessQueue, ^{
queue = self->_operationQueue;
});
return queue;
}
///--------------------------------------
#pragma mark - Perform
///--------------------------------------
- (void)performDelegateBlock:(SRDelegateBlock)block
{
__block __strong id<SRWebSocketDelegate> delegate = nil;
__block SRDelegateAvailableMethods availableMethods;
dispatch_sync(self.accessQueue, ^{
delegate = self->_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
================================================
FILE: SocketRocket/Internal/IOConsumer/SRIOConsumer.h
================================================
//
// 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 <Foundation/Foundation.h>
@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
================================================
FILE: SocketRocket/Internal/IOConsumer/SRIOConsumer.m
================================================
//
// 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
================================================
FILE: SocketRocket/Internal/IOConsumer/SRIOConsumerPool.h
================================================
//
// 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 <Foundation/Foundation.h>
#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
================================================
FILE: SocketRocket/Internal/IOConsumer/SRIOConsumerPool.m
================================================
//
// 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<SRIOConsumer *> *_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
================================================
FILE: SocketRocket/Internal/NSRunLoop+SRWebSocketPrivate.h
================================================
//
// 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 <SocketRocket/NSRunLoop+SRWebSocket.h>
// Empty function that force links the object file for the category.
extern void import_NSRunLoop_SRWebSocket(void);
================================================
FILE: SocketRocket/Internal/NSURLRequest+SRWebSocketPrivate.h
================================================
//
// 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 <SocketRocket/NSURLRequest+SRWebSocket.h>
// Empty function that force links the object file for the category.
extern void import_NSURLRequest_SRWebSocket(void);
================================================
FILE: SocketRocket/Internal/Proxy/SRProxyConnect.h
================================================
//
// 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/Foundation.h>
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
================================================
FILE: SocketRocket/Internal/Proxy/SRProxyConnect.m
================================================
//
// 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() <NSStreamDelegate>
@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<NSData *> *_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) {
_httpProxyPort = [portValue intValue];
}
}
if ([proxyType isEqualToString:(NSString *)kCFProxyTypeSOCKS]) {
_socksProxyHost = settings[(NSString *)kCFProxyHostNameKey];
NSNumber *portValue = settings[(NSString *)kCFProxyPortNumberKey];
if (portValue)
_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 <rdar://problem/5530166>. 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
================================================
FILE: SocketRocket/Internal/RunLoop/SRRunLoopThread.h
================================================
//
// 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 <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface SRRunLoopThread : NSThread
@property (nonatomic, strong, readonly) NSRunLoop *runLoop;
+ (instancetype)sharedThread;
@end
NS_ASSUME_NONNULL_END
================================================
FILE: SocketRocket/Internal/RunLoop/SRRunLoopThread.m
================================================
//
// 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.qualityOfService = NSQualityOfServiceUserInitiated;
[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
================================================
FILE: SocketRocket/Internal/SRConstants.h
================================================
//
// 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/Foundation.h>
typedef NS_ENUM(uint8_t, 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);
================================================
FILE: SocketRocket/Internal/SRConstants.m
================================================
//
// 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;
}
================================================
FILE: SocketRocket/Internal/Security/SRPinningSecurityPolicy.h
================================================
//
// 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/Foundation.h>
#import <SocketRocket/SRSecurityPolicy.h>
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
================================================
FILE: SocketRocket/Internal/Security/SRPinningSecurityPolicy.m
================================================
//
// 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 <Foundation/Foundation.h>
#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
================================================
FILE: SocketRocket/Internal/Utilities/SRError.h
================================================
//
// 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/Foundation.h>
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
================================================
FILE: SocketRocket/Internal/Utilities/SRError.m
================================================
//
// 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
================================================
FILE: SocketRocket/Internal/Utilities/SRHTTPConnectMessage.h
================================================
//
// 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/Foundation.h>
#import <CFNetwork/CFNetwork.h>
NS_ASSUME_NONNULL_BEGIN
extern CFHTTPMessageRef SRHTTPConnectMessageCreate(NSURLRequest *request,
NSString *securityKey,
uint8_t webSocketProtocolVersion,
NSArray<NSHTTPCookie *> *_Nullable cookies,
NSArray<NSString *> *_Nullable requestedProtocols);
NS_ASSUME_NONNULL_END
================================================
FILE: SocketRocket/Internal/Utilities/SRHTTPConnectMessage.m
================================================
//
// 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) {
host = [host stringByAppendingFormat:@":%@", url.port];
}
return host;
}
CFHTTPMessageRef SRHTTPConnectMessageCreate(NSURLRequest *request,
NSString *securityKey,
uint8_t webSocketProtocolVersion,
NSArray<NSHTTPCookie *> *_Nullable cookies,
NSArray<NSString *> *_Nullable requestedProtocols)
{
NSURL *url = request.URL;
CFHTTPMessageRef message = CFHTTPMessageCreateRequest(NULL, (__bridge CFStringRef)request.HTTPMethod, (__bridge CFURLRef)url, kCFHTTPVersion1_1);
// Set host first so it defaults
CFHTTPMessageSetHeaderFieldValue(message, CFSTR("Host"), (__bridge CFStringRef)_SRHTTPConnectMessageHost(url));
// Apply cookies if any have been provided
if (cookies) {
NSDictionary<NSString *, NSString *> *messageCookies = [NSHTTPCookie requestHeaderFieldsWithCookies:(NSArray<NSHTTPCookie*> *_Nonnull)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
================================================
FILE: SocketRocket/Internal/Utilities/SRHash.h
================================================
//
// 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/Foundation.h>
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
================================================
FILE: SocketRocket/Internal/Utilities/SRHash.m
================================================
//
// 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 <CommonCrypto/CommonDigest.h>
NS_ASSUME_NONNULL_BEGIN
NSData *SRSHA1HashFromString(NSString *string)
{
const char *utf8String = string.UTF8String;
if (!utf8String) {
return [NSData data];
}
size_t length = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
return SRSHA1HashFromBytes(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
================================================
FILE: SocketRocket/Internal/Utilities/SRLog.h
================================================
//
// 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/Foundation.h>
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
================================================
FILE: SocketRocket/Internal/Utilities/SRLog.m
================================================
//
// 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
================================================
FILE: SocketRocket/Internal/Utilities/SRMutex.h
================================================
//
// 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/Foundation.h>
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
================================================
FILE: SocketRocket/Internal/Utilities/SRMutex.m
================================================
//
// 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 <pthread/pthread.h>
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
================================================
FILE: SocketRocket/Internal/Utilities/SRRandom.h
================================================
//
// 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/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
extern NSData *SRRandomData(NSUInteger length);
NS_ASSUME_NONNULL_END
================================================
FILE: SocketRocket/Internal/Utilities/SRRandom.m
================================================
//
// 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 <Security/SecRandom.h>
NS_ASSUME_NONNULL_BEGIN
NSData *SRRandomData(NSUInteger length)
{
NSMutableData *_Nullable data = [NSMutableData dataWithLength:length];
if (data == nil) {
[NSException raise:NSInternalInconsistencyException format:@"Failed to allocate random data"];
}
int result = SecRandomCopyBytes(kSecRandomDefault, data.length, ((NSMutableData *_Nonnull)data).mutableBytes);
if (result != errSecSuccess) {
[NSException raise:NSInternalInconsistencyException format:@"Failed to generate random bytes with OSStatus: %d", result];
}
return (NSMutableData *_Nonnull)data;
}
NS_ASSUME_NONNULL_END
================================================
FILE: SocketRocket/Internal/Utilities/SRSIMDHelpers.h
================================================
//
// 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/Foundation.h>
/**
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);
================================================
FILE: SocketRocket/Internal/Utilities/SRSIMDHelpers.m
================================================
//
// 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);
}
================================================
FILE: SocketRocket/Internal/Utilities/SRURLUtilities.h
================================================
//
// 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/Foundation.h>
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 *_Nullable 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
================================================
FILE: SocketRocket/Internal/Utilities/SRURLUtilities.m
================================================
//
// 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 ||
([scheme isEqualToString:@"http"] && port.integerValue == 80) ||
([scheme isEqualToString:@"https"] && port.integerValue == 443));
if (!portIsDefault) {
[origin appendFormat:@":%@", port.stringValue];
}
return origin;
}
extern BOOL SRURLRequiresSSL(NSURL *_Nullable url)
{
NSString *scheme = url.scheme.lowercaseString;
return ([scheme isEqualToString:@"wss"] || [scheme isEqualToString:@"https"]);
}
extern NSString *_Nullable SRBasicAuthorizationHeaderFromURL(NSURL *url)
{
if (!url.user || !url.password) {
return nil;
}
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:
case NSURLNetworkServiceTypeResponsiveData:
case NSURLNetworkServiceTypeAVStreaming:
case NSURLNetworkServiceTypeResponsiveAV:
break;
case NSURLNetworkServiceTypeVoIP:
networkServiceType = NSStreamNetworkServiceTypeVoIP;
break;
case NSURLNetworkServiceTypeVideo:
networkServiceType = NSStreamNetworkServiceTypeVideo;
break;
case NSURLNetworkServiceTypeBackground:
networkServiceType = NSStreamNetworkServiceTypeBackground;
break;
case NSURLNetworkServiceTypeVoice:
networkServiceType = NSStreamNetworkServiceTypeVoice;
break;
#if (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 || __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 || __TV_OS_VERSION_MAX_ALLOWED >= 100000 || __WATCH_OS_VERSION_MAX_ALLOWED >= 30000)
case NSURLNetworkServiceTypeCallSignaling: {
if (@available(iOS 10.0, tvOS 10.0, macOS 10.12, *)) {
networkServiceType = NSStreamNetworkServiceTypeCallSignaling;
}
break;
}
#endif
}
return networkServiceType;
}
NS_ASSUME_NONNULL_END
================================================
FILE: SocketRocket/NSRunLoop+SRWebSocket.h
================================================
//
// 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 <Foundation/Foundation.h>
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
================================================
FILE: SocketRocket/NSRunLoop+SRWebSocket.m
================================================
//
// 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(void) { }
@implementation NSRunLoop (SRWebSocket)
+ (NSRunLoop *)SR_networkRunLoop
{
return [SRRunLoopThread sharedThread].runLoop;
}
@end
================================================
FILE: SocketRocket/NSURLRequest+SRWebSocket.h
================================================
//
// 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 <Foundation/Foundation.h>
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
================================================
FILE: SocketRocket/NSURLRequest+SRWebSocket.m
================================================
//
// 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(void) { }
NS_ASSUME_NONNULL_BEGIN
@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
================================================
FILE: SocketRocket/Resources/Info.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
================================================
FILE: SocketRocket/SRSecurityPolicy.h
================================================
//
// 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/Foundation.h>
#import <Security/Security.h>
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
================================================
FILE: SocketRocket/SRSecurityPolicy.m
================================================
//
// 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<NSString *, id> *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
================================================
FILE: SocketRocket/SRWebSocket.h
================================================
//
// 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 <Foundation/Foundation.h>
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.
SRStatusCodeNoStatusReceived = 1005,
SRStatusNoStatusReceived __deprecated_enum_msg("Use SRStatusCodeNoStatusReceived") = SRStatusCodeNoStatusReceived,
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 <NSStreamDelegate>
/**
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 <SRWebSocketDelegate> 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<NSHTTPCookie *> *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<NSString *> *)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<NSString *> *)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<NSString *> *)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<NSString *> *)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<NSString *> *)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 <NSObject>
@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
================================================
FILE: SocketRocket/SRWebSocket.m
================================================
//
// 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 __has_include(<unicode/utf8.h>)
#define HAS_ICU
#endif
#ifdef HAS_ICU
#import <unicode/utf8.h>
#endif
#import <os/lock.h>
#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(void)
{
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;
// Max frame payload length for all frames is 256MB, which is reasonable max.
static const uint32_t SRWebSocketMaxFramePayloadLength = 256 * 1024 * 1024;
NSString *const SRWebSocketErrorDomain = @"SRWebSocketErrorDomain";
NSString *const SRHTTPResponseErrorKey = @"HTTPResponseStatusCode";
@interface SRWebSocket () <NSStreamDelegate>
@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;
os_unfair_lock _propertyLock;
dispatch_queue_t _workQueue;
NSMutableArray<SRIOConsumer *> *_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<NSArray *> *_scheduledRunloops; // Set<[RunLoop, Mode]>. TODO: (nlutsenko) Fix clowntown
// We use this to retain ourselves.
__strong SRWebSocket *_selfRetain;
NSArray<NSString *> *_requestedProtocols;
SRIOConsumerPool *_consumerPool;
// proxy support
SRProxyConnect *_proxyConnect;
}
@synthesize readyState = _readyState;
///--------------------------------------
#pragma mark - Init
///--------------------------------------
- (instancetype)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray<NSString *> *)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_UNFAIR_LOCK_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<NSString *> *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates
{
SRSecurityPolicy *securityPolicy;
NSArray *pinnedCertificates = request.SR_SSLPinnedCertificates;
if (pinnedCertificates) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
securityPolicy = [SRSecurityPolicy pinnningPolicyWithCertificates:pinnedCertificates];
#pragma clang diagnostic pop
} else {
BOOL certificateChainValidationEnabled = !allowsUntrustedSSLCertificates;
securityPolicy = [[SRSecurityPolicy alloc] initWithCertificateChainValidationEnabled:certificateChainValidationEnabled];
}
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<NSString *> *)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<NSString *> *)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<NSString *> *)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"];
os_unfair_lock_lock(&_propertyLock);
_readyState = readyState;
os_unfair_lock_unlock(&_propertyLock);
[self didChangeValueForKey:@"readyState"];
}
}
@finally {
SRMutexUnlock(_kvoLock);
}
}
- (SRReadyState)readyState
{
SRReadyState state = 0;
os_unfair_lock_lock(&_propertyLock);
state = _readyState;
os_unfair_lock_unlock(&_propertyLock);
return state;
}
+ (BOOL)automaticallyNotifiesObserversOfReadyState {
return NO;
}
///--------------------------------------
#pragma mark - Open / Close
///--------------------------------------
- (void)open
{
NSURL* const url = _url;
if (!url) {
NSError *error = SRErrorWithDomainCodeDescription(NSURLErrorDomain, NSURLErrorBadURL, @"Unable to open socket with emtpy URL.");
[self _failWithError:error];
return;
}
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));
__weak typeof(self) wself = self;
dispatch_after(popTime, dispatch_get_main_queue(), ^{
__strong SRWebSocket *sself = wself;
if (!sself) {
return;
}
if (sself.readyState == SR_CONNECTING) {
NSError *error = SRErrorWithDomainCodeDescription(NSURLErrorDomain, NSURLErrorTimedOut, @"Timed out connecting to server.");
[sself _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, ^{
self->_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:(CFHTTPMessageRef)httpMessage
{
NSInteger responseCode = CFHTTPMessageGetResponseStatusCode(httpMessage);
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:httpMessage]) {
NSError *error = SRErrorWithCodeDescription(2133, @"Invalid Sec-WebSocket-Accept response.");
[self _failWithError:error];
return;
}
NSString *negotiatedProtocol = CFBridgingRelease(CFHTTPMessageCopyHeaderFieldValue(httpMessage, 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<SRWebSocketDelegate> _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) {
if (!socket) {
return;
}
CFHTTPMessageRef receivedHTTPHeaders = socket->_receivedHTTPHeaders;
CFHTTPMessageAppendBytes(receivedHTTPHeaders, (const UInt8 *)data.bytes, data.length);
if (CFHTTPMessageIsHeaderComplete(receivedHTTPHeaders)) {
SRDebugLog(@"Finished reading headers %@", CFBridgingRelease(CFHTTPMessageCopyAllHeaderFields(receivedHTTPHeaders)));
[socket _HTTPHeadersDidFinish:receivedHTTPHeaders];
} else {
[socket _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);
__weak typeof(self) wself = self;
dispatch_async(_workQueue, ^{
__strong SRWebSocket *sself = wself;
if (!sself) {
return;
}
if (sself.readyState == SR_CLOSING || sself.readyState == SR_CLOSED) {
return;
}
BOOL wasConnecting = sself.readyState == SR_CONNECTING;
sself.readyState = SR_CLOSING;
SRDebugLog(@"Closing with code %d reason %@", code, reason);
if (wasConnecting) {
[sself 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))];
}
}
[sself _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(self->_workQueue, ^{
[self closeConnection];
});
}];
}
- (void)_failWithError:(NSError *)error
{
dispatch_async(_workQueue, ^{
if (self.readyState != SR_CLOSED) {
self->_failed = YES;
[self.delegateController performDelegateBlock:^(id<SRWebSocketDelegate> _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;
});
(void)strongData;
_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:(NSString *_Nonnull)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<SRWebSocketDelegate> _Nullable delegate, SRDelegateAvailableMethods availableMethods) {
if (availableMethods.didReceivePing) {
[delegate webSocket:self didReceivePingWithData:data];
}
dispatch_async(self->_workQueue, ^{
[self _sendFrameWithOpcode:SROpCodePong data:data];
});
}];
}
- (void)handlePong:(NSData *)pongData
{
SRDebugLog(@"Received pong");
[self.delegateController performDelegateBlock:^(id<SRWebSocketDelegate> _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 = SRStatusCodeNoStatusReceived;
}
[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<SRWebSocketDelegate> _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<SRWebSocketDelegate> _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 {
if (frame_header.payload_length > SRWebSocketMaxFramePayloadLength) {
[self _closeWithProtocolError:@"Payload length too large."];
return;
}
[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(sself->_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(eself->_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).
self->_currentFrameData = [[NSMutableData alloc] init];
self->_currentFrameOpcode = 0;
self->_currentFrameCount = 0;
self->_readOpCount = 0;
self->_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.readyState = SR_CLOSED;
[self.delegateController performDelegateBlock:^(id<SRWebSocketDelegate> _Nullable delegate, SRDelegateAvailableMethods availableMethods) {
if (availableMethods.didCloseWithCode) {
[delegate webSocket:self didCloseWithCode:self->_closeCode reason:self->_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, ^{
self->_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);
NSData *randomData = SRRandomData(randomBytesSize);
[randomData getBytes:maskKey range:NSMakeRange(0, randomBytesSize)];
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) {
NSString *const host = _urlRequest.URL.host;
if (!host || host.length == 0) {
dispatch_async(_workQueue, ^{
NSError *error = SRErrorWithDomainCodeDescription(NSURLErrorDomain,
NSURLErrorBadURL,
@"Unable to validate certificate for empty host.");
[wself _failWithError:error];
});
return;
}
_streamSecurityValidated = [_securityPolicy evaluateServerTrust:trust forDomain: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 (!self->_sentClose && !self->_failed) {
self->_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<SRWebSocketDelegate> _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<SRWebSocketDelegate> _Nullable)delegate
{
return self.delegateController.delegate;
}
- (void)setDelegate:(id<SRWebSocketDelegate> _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
================================================
FILE: SocketRocket/SocketRocket.h
================================================
//
// 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 <SocketRocket/NSRunLoop+SRWebSocket.h>
#import <SocketRocket/NSURLRequest+SRWebSocket.h>
#import <SocketRocket/SRSecurityPolicy.h>
#import <SocketRocket/SRWebSocket.h>
================================================
FILE: SocketRocket.podspec
================================================
Pod::Spec.new do |s|
s.name = 'SocketRocket'
s.version = '0.7.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 = '11.0'
s.osx.deployment_target = '10.13'
s.tvos.deployment_target = '11.0'
s.visionos.deployment_target = '1.0'
s.ios.frameworks = 'CFNetwork', 'Security'
s.osx.frameworks = 'CoreServices', 'Security'
s.tvos.frameworks = 'CFNetwork', 'Security'
s.libraries = 'icucore'
end
================================================
FILE: SocketRocket.xcodeproj/project.pbxproj
================================================
// !$*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 */; };
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 */; };
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 */; };
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 */; };
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 */; };
81DCD1241D2D9235002501A2 /* libicucore.A.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 81C68D0D1D2CBFA800A1D005 /* libicucore.A.tbd */; };
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 */; };
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 */
81E8A6A01D4C41DA00916C7E /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = F6B208241450F597009315AF /* Project object */;
proxyType = 1;
remoteGlobalIDString = 2D4227611BB4358C000C1A6C;
remoteInfo = "SocketRocket-iOS-Dynamic";
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
81E8A6A61D4C41E000916C7E /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
);
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 = "<group>"; };
454FEA7A1D2570D400073768 /* SRPinningSecurityPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRPinningSecurityPolicy.m; sourceTree = "<group>"; };
454FEA831D25717C00073768 /* SRSecurityPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRSecurityPolicy.m; sourceTree = "<group>"; };
4861E7731D022211002FAB1D /* SRProxyConnect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRProxyConnect.h; sourceTree = "<group>"; };
4861E7741D022211002FAB1D /* SRProxyConnect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRProxyConnect.m; sourceTree = "<group>"; };
555E0EB11C51E56D00E6BB92 /* SocketRocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocketRocket.h; sourceTree = "<group>"; };
8105E4761CDD679A00AA12DB /* SRTWebSocketOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SRTWebSocketOperation.h; sourceTree = "<group>"; };
8105E4771CDD679A00AA12DB /* SRTWebSocketOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SRTWebSocketOperation.m; sourceTree = "<group>"; };
8105E4791CDD679A00AA12DB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8105E47A1CDD679A00AA12DB /* SRAutobahnTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SRAutobahnTests.m; sourceTree = "<group>"; };
8105E4AC1CDD6E6200AA12DB /* SRAutobahnOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRAutobahnOperation.h; sourceTree = "<group>"; };
8105E4AD1CDD6E6200AA12DB /* SRAutobahnOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRAutobahnOperation.m; sourceTree = "<group>"; };
8105E5271CDD98E100AA12DB /* autobahn_configuration.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = autobahn_configuration.json; sourceTree = "<group>"; };
8117C4221D3076DF00784D79 /* NSURLRequest+SRWebSocketPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSURLRequest+SRWebSocketPrivate.h"; path = "Internal/NSURLRequest+SRWebSocketPrivate.h"; sourceTree = "<group>"; };
8117C42F1D30779900784D79 /* NSRunLoop+SRWebSocketPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSRunLoop+SRWebSocketPrivate.h"; path = "Internal/NSRunLoop+SRWebSocketPrivate.h"; sourceTree = "<group>"; };
811934B11CDAF711003AB243 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
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 = "<group>"; };
817491A71D1C8C33006E09DF /* SRMutex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRMutex.m; sourceTree = "<group>"; };
817995841CE139700084DA37 /* SRDelegateController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRDelegateController.h; sourceTree = "<group>"; };
817995851CE139700084DA37 /* SRDelegateController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRDelegateController.m; sourceTree = "<group>"; };
8179967E1CE184F40084DA37 /* SRAutobahnUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRAutobahnUtilities.h; sourceTree = "<group>"; };
8179967F1CE184F40084DA37 /* SRAutobahnUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRAutobahnUtilities.m; sourceTree = "<group>"; };
81900A4A1D18C9CC0015A290 /* SRLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRLog.h; sourceTree = "<group>"; };
81900A4B1D18C9CC0015A290 /* SRLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRLog.m; sourceTree = "<group>"; };
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 = "<group>"; };
81B22EC41CE42D7E0073C636 /* SRError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRError.m; sourceTree = "<group>"; };
81B22EE21CE43ECC0073C636 /* SRURLUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRURLUtilities.h; sourceTree = "<group>"; };
81B22EE31CE43ECC0073C636 /* SRURLUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRURLUtilities.m; sourceTree = "<group>"; };
81B31C0F1CDC404100D86D43 /* SRIOConsumer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRIOConsumer.h; sourceTree = "<group>"; };
81B31C101CDC404100D86D43 /* SRIOConsumer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRIOConsumer.m; sourceTree = "<group>"; };
81B31C111CDC404100D86D43 /* SRIOConsumerPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SRIOConsumerPool.h; sourceTree = "<group>"; };
81B31C121CDC404100D86D43 /* SRIOConsumerPool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SRIOConsumerPool.m; so
gitextract_2hs1q41a/
├── .gitignore
├── .gitmodules
├── .ruby-version
├── .travis.yml
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── Configurations/
│ ├── SocketRocket-iOS-Dynamic.xcconfig
│ ├── SocketRocket-iOS.xcconfig
│ ├── SocketRocket-macOS.xcconfig
│ ├── SocketRocket-tvOS.xcconfig
│ ├── SocketRocketTests-iOS.xcconfig
│ └── TestChat-iOS.xcconfig
├── Gemfile
├── LICENSE
├── LICENSE-examples
├── Makefile
├── PATENTS
├── README.md
├── SocketRocket/
│ ├── Internal/
│ │ ├── Delegate/
│ │ │ ├── SRDelegateController.h
│ │ │ └── SRDelegateController.m
│ │ ├── IOConsumer/
│ │ │ ├── SRIOConsumer.h
│ │ │ ├── SRIOConsumer.m
│ │ │ ├── SRIOConsumerPool.h
│ │ │ └── SRIOConsumerPool.m
│ │ ├── NSRunLoop+SRWebSocketPrivate.h
│ │ ├── NSURLRequest+SRWebSocketPrivate.h
│ │ ├── Proxy/
│ │ │ ├── SRProxyConnect.h
│ │ │ └── SRProxyConnect.m
│ │ ├── RunLoop/
│ │ │ ├── SRRunLoopThread.h
│ │ │ └── SRRunLoopThread.m
│ │ ├── SRConstants.h
│ │ ├── SRConstants.m
│ │ ├── Security/
│ │ │ ├── SRPinningSecurityPolicy.h
│ │ │ └── SRPinningSecurityPolicy.m
│ │ └── Utilities/
│ │ ├── SRError.h
│ │ ├── SRError.m
│ │ ├── SRHTTPConnectMessage.h
│ │ ├── SRHTTPConnectMessage.m
│ │ ├── SRHash.h
│ │ ├── SRHash.m
│ │ ├── SRLog.h
│ │ ├── SRLog.m
│ │ ├── SRMutex.h
│ │ ├── SRMutex.m
│ │ ├── SRRandom.h
│ │ ├── SRRandom.m
│ │ ├── SRSIMDHelpers.h
│ │ ├── SRSIMDHelpers.m
│ │ ├── SRURLUtilities.h
│ │ └── SRURLUtilities.m
│ ├── NSRunLoop+SRWebSocket.h
│ ├── NSRunLoop+SRWebSocket.m
│ ├── NSURLRequest+SRWebSocket.h
│ ├── NSURLRequest+SRWebSocket.m
│ ├── Resources/
│ │ └── Info.plist
│ ├── SRSecurityPolicy.h
│ ├── SRSecurityPolicy.m
│ ├── SRWebSocket.h
│ ├── SRWebSocket.m
│ └── SocketRocket.h
├── SocketRocket.podspec
├── SocketRocket.xcodeproj/
│ ├── project.pbxproj
│ └── xcshareddata/
│ └── xcschemes/
│ ├── SocketRocket-iOS-Dynamic.xcscheme
│ ├── SocketRocket-iOS.xcscheme
│ ├── SocketRocket-macOS.xcscheme
│ ├── SocketRocket-tvOS.xcscheme
│ ├── SocketRocketTests.xcscheme
│ └── TestChat.xcscheme
├── TestChat/
│ ├── TCAppDelegate.h
│ ├── TCAppDelegate.m
│ ├── TCChatCell.h
│ ├── TCChatCell.m
│ ├── TCViewController.h
│ ├── TCViewController.m
│ ├── TestChat-Info.plist
│ ├── en.lproj/
│ │ ├── InfoPlist.strings
│ │ └── MainStoryboard.storyboard
│ └── main.m
├── TestChatServer/
│ ├── go/
│ │ ├── README
│ │ └── chatroom.go
│ ├── py/
│ │ └── chatroom.py
│ └── static/
│ ├── .gitignore
│ ├── index.html
│ └── proxy.js
├── TestSupport/
│ ├── autobahn_fuzzingserver.json
│ ├── run_test_server.sh
│ └── setup_env.sh
└── Tests/
├── Operations/
│ ├── SRAutobahnOperation.h
│ ├── SRAutobahnOperation.m
│ ├── SRTWebSocketOperation.h
│ └── SRTWebSocketOperation.m
├── Resources/
│ ├── Info.plist
│ └── autobahn_configuration.json
├── SRAutobahnTests.m
└── Utilities/
├── SRAutobahnUtilities.h
└── SRAutobahnUtilities.m
SYMBOL INDEX (15 symbols across 5 files)
FILE: SocketRocket/Internal/Delegate/SRDelegateController.h
type SRDelegateAvailableMethods (line 18) | struct SRDelegateAvailableMethods {
type SRDelegateAvailableMethods (line 32) | struct SRDelegateAvailableMethods {
type SRDelegateAvailableMethods (line 46) | typedef struct SRDelegateAvailableMethods SRDelegateAvailableMethods;
FILE: SocketRocket/Internal/IOConsumer/SRIOConsumer.h
function interface (line 21) | interface SRIOConsumer : NSObject {
FILE: TestChatServer/go/chatroom.go
type Msg (line 18) | type Msg struct
function run (line 23) | func run(reg chan *websocket.Conn, unreg chan *websocket.Conn, msg chan ...
function newChatServer (line 41) | func newChatServer(reg chan *websocket.Conn, unreg chan *websocket.Conn,...
function main (line 56) | func main() {
FILE: TestChatServer/py/chatroom.py
function parse_args (line 29) | def parse_args():
class ChatHandler (line 46) | class ChatHandler(tornado.websocket.WebSocketHandler):
method open (line 47) | def open(self):
method on_message (line 51) | def on_message(self, msg):
method on_close (line 57) | def on_close(self):
function main (line 61) | def main():
FILE: TestChatServer/static/proxy.js
function SocketClient (line 10) | function SocketClient () {
Condensed preview — 96 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (329K chars).
[
{
"path": ".gitignore",
"chars": 301,
"preview": ".idea/\n.env/\n*.egg-info\nreports/\nbuild/\nnohup.out\n.DS_Store\nxcuserdata/\n*.pbxuser\n!default.pbxuser\n*.mode1v3\n!default.mo"
},
{
"path": ".gitmodules",
"chars": 112,
"preview": "[submodule \"Vendor/xctoolchain\"]\n\tpath = Vendor/xctoolchain\n\turl = https://github.com/nlutsenko/xctoolchain.git\n"
},
{
"path": ".ruby-version",
"chars": 6,
"preview": "2.3.1\n"
},
{
"path": ".travis.yml",
"chars": 1266,
"preview": "branches:\n only:\n - master\nlanguage: objective-c\nos: osx\nosx_image: xcode7.3\nenv:\n matrix:\n - TEST_TYPE=iOS\n "
},
{
"path": "CODE_OF_CONDUCT.md",
"chars": 241,
"preview": "# Code of Conduct\nFacebook has adopted a Code of Conduct that we expect project participants to adhere to. Please [read "
},
{
"path": "CONTRIBUTING.md",
"chars": 1363,
"preview": "# Contributing to SocketRocket\nWe want to make contributing to this project as easy and transparent as possible.\n\n## Pul"
},
{
"path": "Configurations/SocketRocket-iOS-Dynamic.xcconfig",
"chars": 584,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "Configurations/SocketRocket-iOS.xcconfig",
"chars": 684,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "Configurations/SocketRocket-macOS.xcconfig",
"chars": 587,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "Configurations/SocketRocket-tvOS.xcconfig",
"chars": 582,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "Configurations/SocketRocketTests-iOS.xcconfig",
"chars": 627,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "Configurations/TestChat-iOS.xcconfig",
"chars": 607,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "Gemfile",
"chars": 62,
"preview": "source 'https://rubygems.org'\n\ngem 'cocoapods'\ngem 'xcpretty'\n"
},
{
"path": "LICENSE",
"chars": 1532,
"preview": "BSD License\n\nFor SocketRocket software\n\nCopyright (c) 2016-present, Facebook, Inc. All rights reserved.\n\nRedistribution "
},
{
"path": "LICENSE-examples",
"chars": 650,
"preview": "Copyright (c) 2016-present, Facebook, Inc. All rights reserved.\n\nThe examples provided by Facebook are for non-commercia"
},
{
"path": "Makefile",
"chars": 707,
"preview": "TEST_SCENARIOS=\"[1-8]*\"\nTEST_URL='ws://localhost:9001/'\n\nall:\n\t$(MAKE) -C SocketRocket\n\nclean:\n\t$(MAKE) -C SocketRocket "
},
{
"path": "PATENTS",
"chars": 1981,
"preview": "Additional Grant of Patent Rights Version 2\n\n\"Software\" means the SocketRocket software distributed by Facebook, Inc.\n\nF"
},
{
"path": "README.md",
"chars": 6723,
"preview": "# SocketRocket\n\n![Platforms][platforms-svg]\n[![License][license-svg]][license-link]\n\n[![Podspec][podspec-svg]][podspec-l"
},
{
"path": "SocketRocket/Internal/Delegate/SRDelegateController.h",
"chars": 1868,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Delegate/SRDelegateController.m",
"chars": 4408,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/IOConsumer/SRIOConsumer.h",
"chars": 1418,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/Internal/IOConsumer/SRIOConsumer.m",
"chars": 1061,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/Internal/IOConsumer/SRIOConsumerPool.h",
"chars": 1029,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/Internal/IOConsumer/SRIOConsumerPool.m",
"chars": 1744,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/Internal/NSRunLoop+SRWebSocketPrivate.h",
"chars": 473,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/NSURLRequest+SRWebSocketPrivate.h",
"chars": 479,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Proxy/SRProxyConnect.h",
"chars": 780,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Proxy/SRProxyConnect.m",
"chars": 16723,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/RunLoop/SRRunLoopThread.h",
"chars": 569,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/Internal/RunLoop/SRRunLoopThread.m",
"chars": 2079,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/Internal/SRConstants.h",
"chars": 684,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/SRConstants.m",
"chars": 520,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Security/SRPinningSecurityPolicy.h",
"chars": 897,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Security/SRPinningSecurityPolicy.m",
"chars": 2414,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRError.h",
"chars": 818,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRError.m",
"chars": 1534,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRHTTPConnectMessage.h",
"chars": 854,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRHTTPConnectMessage.m",
"chars": 3183,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRHash.h",
"chars": 579,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRHash.m",
"chars": 1324,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRLog.h",
"chars": 564,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRLog.m",
"chars": 771,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRMutex.h",
"chars": 718,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRMutex.m",
"chars": 1078,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRRandom.h",
"chars": 439,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRRandom.m",
"chars": 989,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRSIMDHelpers.h",
"chars": 616,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRSIMDHelpers.m",
"chars": 2584,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRURLUtilities.h",
"chars": 933,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/Internal/Utilities/SRURLUtilities.m",
"chars": 3032,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/NSRunLoop+SRWebSocket.h",
"chars": 635,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/NSRunLoop+SRWebSocket.m",
"chars": 684,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/NSURLRequest+SRWebSocket.h",
"chars": 1355,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/NSURLRequest+SRWebSocket.m",
"chars": 1103,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/Resources/Info.plist",
"chars": 806,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
},
{
"path": "SocketRocket/SRSecurityPolicy.h",
"chars": 2653,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/SRSecurityPolicy.m",
"chars": 2108,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "SocketRocket/SRWebSocket.h",
"chars": 15612,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/SRWebSocket.m",
"chars": 57022,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket/SocketRocket.h",
"chars": 526,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "SocketRocket.podspec",
"chars": 1022,
"preview": "Pod::Spec.new do |s|\n s.name = 'SocketRocket'\n s.version = '0.7.1'\n s.summary = '"
},
{
"path": "SocketRocket.xcodeproj/project.pbxproj",
"chars": 76106,
"preview": "// !$*UTF8*$!\n{\n\tarchiveVersion = 1;\n\tclasses = {\n\t};\n\tobjectVersion = 46;\n\tobjects = {\n\n/* Begin PBXBuildFile section *"
},
{
"path": "SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-iOS-Dynamic.xcscheme",
"chars": 2825,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Scheme\n LastUpgradeVersion = \"1250\"\n version = \"1.3\">\n <BuildAction\n "
},
{
"path": "SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-iOS.xcscheme",
"chars": 6460,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Scheme\n LastUpgradeVersion = \"1250\"\n version = \"1.7\">\n <BuildAction\n "
},
{
"path": "SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-macOS.xcscheme",
"chars": 2807,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Scheme\n LastUpgradeVersion = \"1250\"\n version = \"1.3\">\n <BuildAction\n "
},
{
"path": "SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocket-tvOS.xcscheme",
"chars": 2421,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Scheme\n LastUpgradeVersion = \"1250\"\n version = \"1.3\">\n <BuildAction\n "
},
{
"path": "SocketRocket.xcodeproj/xcshareddata/xcschemes/SocketRocketTests.xcscheme",
"chars": 3592,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Scheme\n LastUpgradeVersion = \"0730\"\n version = \"1.3\">\n <BuildAction\n "
},
{
"path": "SocketRocket.xcodeproj/xcshareddata/xcschemes/TestChat.xcscheme",
"chars": 3926,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Scheme\n LastUpgradeVersion = \"0730\"\n version = \"1.3\">\n <BuildAction\n "
},
{
"path": "TestChat/TCAppDelegate.h",
"chars": 393,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// Th"
},
{
"path": "TestChat/TCAppDelegate.m",
"chars": 443,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// Th"
},
{
"path": "TestChat/TCChatCell.h",
"chars": 442,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// Th"
},
{
"path": "TestChat/TCChatCell.m",
"chars": 1086,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// Th"
},
{
"path": "TestChat/TCViewController.h",
"chars": 464,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// Th"
},
{
"path": "TestChat/TCViewController.m",
"chars": 5023,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// Th"
},
{
"path": "TestChat/TestChat-Info.plist",
"chars": 1257,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
},
{
"path": "TestChat/en.lproj/InfoPlist.strings",
"chars": 45,
"preview": "/* Localized versions of Info.plist keys */\n\n"
},
{
"path": "TestChat/en.lproj/MainStoryboard.storyboard",
"chars": 10475,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<document type=\"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard"
},
{
"path": "TestChat/main.m",
"chars": 461,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// Th"
},
{
"path": "TestChatServer/go/README",
"chars": 48,
"preview": "With the latest weekly go:\n\n\tgo run chatroom.go\n"
},
{
"path": "TestChatServer/go/chatroom.go",
"chars": 1478,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n// \n// T"
},
{
"path": "TestChatServer/py/chatroom.py",
"chars": 2211,
"preview": "#!/usr/bin/env python\n#\n# Copyright 2012 Square Inc.\n# Portions Copyright (c) 2016-present, Facebook, Inc.\n# All rights "
},
{
"path": "TestChatServer/static/.gitignore",
"chars": 10,
"preview": "devtools/\n"
},
{
"path": "TestChatServer/static/index.html",
"chars": 747,
"preview": "<!DOCTYPE HTML>\n<html>\n <head>\n <script src='proxy.js'>\n </script>\n <style type='text/css'>\n html {\n "
},
{
"path": "TestChatServer/static/proxy.js",
"chars": 2688,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n// \n// T"
},
{
"path": "TestSupport/autobahn_fuzzingserver.json",
"chars": 141,
"preview": "{\n \"url\": \"ws://127.0.0.1:9001\",\n \"outdir\": \"./pages/results\",\n \"cases\": [\"*\"],\n \"exclude-cases\": [],\n \"exclud"
},
{
"path": "TestSupport/run_test_server.sh",
"chars": 495,
"preview": "#\n# Copyright (c) 2016-present, Facebook, Inc.\n# All rights reserved.\n#\n# This source code is licensed under the license"
},
{
"path": "TestSupport/setup_env.sh",
"chars": 717,
"preview": "#\n# Copyright (c) 2016-present, Facebook, Inc.\n# All rights reserved.\n#\n# This source code is licensed under the license"
},
{
"path": "Tests/Operations/SRAutobahnOperation.h",
"chars": 1950,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "Tests/Operations/SRAutobahnOperation.m",
"chars": 6351,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "Tests/Operations/SRTWebSocketOperation.h",
"chars": 997,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "Tests/Operations/SRTWebSocketOperation.m",
"chars": 2246,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "Tests/Resources/Info.plist",
"chars": 674,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
},
{
"path": "Tests/Resources/autobahn_configuration.json",
"chars": 345,
"preview": "{\n \"UNIMPLEMENTED\": [\n \"12\",\n \"13\"\n ],\n \"NON-STRICT"
},
{
"path": "Tests/SRAutobahnTests.m",
"chars": 5199,
"preview": "//\n// Copyright 2012 Square Inc.\n// Portions Copyright (c) 2016-present, Facebook, Inc.\n//\n// All rights reserved.\n//\n//"
},
{
"path": "Tests/Utilities/SRAutobahnUtilities.h",
"chars": 1290,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
},
{
"path": "Tests/Utilities/SRAutobahnUtilities.m",
"chars": 4312,
"preview": "//\n// Copyright (c) 2016-present, Facebook, Inc.\n// All rights reserved.\n//\n// This source code is licensed under the BS"
}
]
About this extraction
This page contains the full source code of the facebookincubator/SocketRocket GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 96 files (302.2 KB), approximately 82.8k tokens, and a symbol index with 15 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.