appjam 0.1.8.8 → 0.1.8.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -62
- data/lib/appjam/generators/gist.yml +1 -1
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.pbxproj +1166 -482
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Prefix.pch.tt +26 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/AwesomeMenu.h +52 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/AwesomeMenu.m +412 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/AwesomeMenuItem.h +44 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/AwesomeMenuItem.m +97 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/bg-addbutton-highlighted.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/bg-addbutton-highlighted@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/bg-addbutton.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/bg-addbutton@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/bg-menuitem-highlighted.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/bg-menuitem-highlighted@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/bg-menuitem.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/bg-menuitem@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/icon-plus-highlighted.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/icon-plus-highlighted@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/icon-plus.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/icon-plus@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/icon-star.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/AwesomeMenu/Images/icon-star@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/CMPopTipView/CMPopTipView.h +167 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/CMPopTipView/CMPopTipView.m +639 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/FXLabel/FXLabel.h +97 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/FXLabel/FXLabel.m +1080 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/MBProgressHUD/MBProgressHUD.h +451 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/MBProgressHUD/MBProgressHUD.m +865 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/FacingView.h +42 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/FacingView.m +56 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/FoldView.h +90 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/FoldView.m +316 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/MultiFoldView.h +104 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/MultiFoldView.m +516 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/PaperFoldConstants.h +49 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/PaperFoldNavigationController.h +18 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/PaperFoldNavigationController.m +88 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/PaperFoldResources.bundle/swipe_guide_left.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/PaperFoldResources.bundle/swipe_guide_left@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/PaperFoldResources.bundle/swipe_guide_right.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/PaperFoldResources.bundle/swipe_guide_right@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/PaperFoldSwipeHintView.h +25 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/PaperFoldSwipeHintView.m +76 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/PaperFoldView.h +131 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/PaperFoldView.m +941 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/Resources/swipe_guide.psd +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/Resources/swipe_guide2.psd +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/ShadowView.h +46 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/ShadowView.m +82 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/TouchThroughUIView.h +39 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/TouchThroughUIView.m +72 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/UIView+Screenshot.h +42 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/PaperFold/UIView+Screenshot.m +100 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/NSBubbleData.h +34 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/NSBubbleData.m +140 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/UIBubbleHeaderTableViewCell.h +17 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/UIBubbleHeaderTableViewCell.m +57 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/UIBubbleTableView.h +30 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/UIBubbleTableView.m +233 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/UIBubbleTableViewCell.h +19 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/UIBubbleTableViewCell.m +122 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/UIBubbleTableViewDataSource.h +24 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/UIBubbleTypingTableViewCell.h +20 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/UIBubbleTypingTableViewCell.m +56 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/images/bubbleMine.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/images/bubbleMine@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/images/bubbleSomeone.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/images/bubbleSomeone@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/images/missingAvatar.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/images/missingAvatar@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/images/typingMine.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/images/typingMine@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/images/typingSomeone.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIBubbleTableView/images/typingSomeone@2x.png +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIGlossyButton/UIGlossyButton.h +124 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIGlossyButton/UIGlossyButton.m +545 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIGlossyButton/UIView+LayerEffects.h +22 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/components/UIGlossyButton/UIView+LayerEffects.m +32 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFIncrementalStore/AFIncrementalStore.h +344 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFIncrementalStore/AFIncrementalStore.m +848 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFIncrementalStore/AFRESTClient.h +135 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFIncrementalStore/AFRESTClient.m +441 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/InflectorKit/NSString+InflectorKit.h +40 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/InflectorKit/NSString+InflectorKit.m +36 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/InflectorKit/TTTStringInflector.h +76 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/InflectorKit/TTTStringInflector.m +270 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/MKAnnotationView+WebCache.h +95 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/MKAnnotationView+WebCache.m +78 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDImageCache.h +144 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDImageCache.m +311 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImageCompat.h +40 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImageCompat.m +54 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImageDecoder.h +18 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImageDecoder.m +70 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImageDownloader.h +102 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImageDownloader.m +226 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImageDownloaderOperation.h +25 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImageDownloaderOperation.m +339 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImageManager.h +167 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImageManager.m +244 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImageOperation.h +15 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImagePrefetcher.h +58 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/SDWebImagePrefetcher.m +127 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/UIButton+WebCache.h +173 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/UIButton+WebCache.m +129 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/UIImageView+WebCache.h +140 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/SDWebImage/UIImageView+WebCache.m +84 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CPAnimationSequence/CPAnimationProgram.h +28 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CPAnimationSequence/CPAnimationSequence.h +28 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CPAnimationSequence/CPAnimationStep.h +49 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CPAnimationSequence/private/CPAnimationProgram.m +100 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CPAnimationSequence/private/CPAnimationSequence.m +85 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CPAnimationSequence/private/CPAnimationStep.m +122 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaAsyncSocket/GCDAsyncSocket.h +1074 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaAsyncSocket/GCDAsyncSocket.m +7430 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Categories/DDData.h +14 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Categories/DDData.m +158 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Categories/DDNumber.h +12 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Categories/DDNumber.m +88 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Categories/DDRange.h +56 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Categories/DDRange.m +104 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/HTTPAuthenticationRequest.h +45 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/HTTPAuthenticationRequest.m +195 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/HTTPConnection.h +119 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/HTTPConnection.m +2708 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/HTTPLogging.h +136 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/HTTPMessage.h +48 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/HTTPMessage.m +113 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/HTTPResponse.h +149 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/HTTPServer.h +205 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/HTTPServer.m +772 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Mime/MultipartFormDataParser.h +65 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Mime/MultipartFormDataParser.m +529 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Mime/MultipartMessageHeader.h +33 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Mime/MultipartMessageHeader.m +86 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Mime/MultipartMessageHeaderField.h +23 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Mime/MultipartMessageHeaderField.m +211 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPAsyncFileResponse.h +75 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPAsyncFileResponse.m +405 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPDataResponse.h +13 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPDataResponse.m +79 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPDynamicFileResponse.h +52 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPDynamicFileResponse.m +292 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPErrorResponse.h +9 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPErrorResponse.m +38 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPFileResponse.h +25 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPFileResponse.m +237 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPRedirectResponse.h +12 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/Responses/HTTPRedirectResponse.m +73 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/WebSocket.h +105 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Core/WebSocket.m +791 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Extensions/WebDAV/DAVConnection.h +7 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Extensions/WebDAV/DAVConnection.m +160 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Extensions/WebDAV/DAVResponse.h +11 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Extensions/WebDAV/DAVResponse.m +372 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Extensions/WebDAV/DELETEResponse.h +7 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Extensions/WebDAV/DELETEResponse.m +49 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Extensions/WebDAV/PUTResponse.h +8 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/CocoaHTTPServer/Extensions/WebDAV/PUTResponse.m +69 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/hpple/TFHpple.h +54 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/hpple/TFHpple.m +102 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/hpple/TFHppleElement.h +103 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/hpple/TFHppleElement.m +200 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/hpple/XPathQuery.h +10 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/hpple/XPathQuery.m +197 -0
- data/lib/appjam/version.rb +1 -1
- metadata +164 -3
@@ -0,0 +1,791 @@
|
|
1
|
+
#import "WebSocket.h"
|
2
|
+
#import "HTTPMessage.h"
|
3
|
+
#import "GCDAsyncSocket.h"
|
4
|
+
#import "DDNumber.h"
|
5
|
+
#import "DDData.h"
|
6
|
+
#import "HTTPLogging.h"
|
7
|
+
|
8
|
+
#if ! __has_feature(objc_arc)
|
9
|
+
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
|
10
|
+
#endif
|
11
|
+
|
12
|
+
// Log levels: off, error, warn, info, verbose
|
13
|
+
// Other flags : trace
|
14
|
+
static const int httpLogLevel = HTTP_LOG_LEVEL_WARN; // | HTTP_LOG_FLAG_TRACE;
|
15
|
+
|
16
|
+
#define TIMEOUT_NONE -1
|
17
|
+
#define TIMEOUT_REQUEST_BODY 10
|
18
|
+
|
19
|
+
#define TAG_HTTP_REQUEST_BODY 100
|
20
|
+
#define TAG_HTTP_RESPONSE_HEADERS 200
|
21
|
+
#define TAG_HTTP_RESPONSE_BODY 201
|
22
|
+
|
23
|
+
#define TAG_PREFIX 300
|
24
|
+
#define TAG_MSG_PLUS_SUFFIX 301
|
25
|
+
#define TAG_MSG_WITH_LENGTH 302
|
26
|
+
#define TAG_MSG_MASKING_KEY 303
|
27
|
+
#define TAG_PAYLOAD_PREFIX 304
|
28
|
+
#define TAG_PAYLOAD_LENGTH 305
|
29
|
+
#define TAG_PAYLOAD_LENGTH16 306
|
30
|
+
#define TAG_PAYLOAD_LENGTH64 307
|
31
|
+
|
32
|
+
#define WS_OP_CONTINUATION_FRAME 0
|
33
|
+
#define WS_OP_TEXT_FRAME 1
|
34
|
+
#define WS_OP_BINARY_FRAME 2
|
35
|
+
#define WS_OP_CONNECTION_CLOSE 8
|
36
|
+
#define WS_OP_PING 9
|
37
|
+
#define WS_OP_PONG 10
|
38
|
+
|
39
|
+
static inline BOOL WS_OP_IS_FINAL_FRAGMENT(UInt8 frame)
|
40
|
+
{
|
41
|
+
return (frame & 0x80) ? YES : NO;
|
42
|
+
}
|
43
|
+
|
44
|
+
static inline BOOL WS_PAYLOAD_IS_MASKED(UInt8 frame)
|
45
|
+
{
|
46
|
+
return (frame & 0x80) ? YES : NO;
|
47
|
+
}
|
48
|
+
|
49
|
+
static inline NSUInteger WS_PAYLOAD_LENGTH(UInt8 frame)
|
50
|
+
{
|
51
|
+
return frame & 0x7F;
|
52
|
+
}
|
53
|
+
|
54
|
+
@interface WebSocket (PrivateAPI)
|
55
|
+
|
56
|
+
- (void)readRequestBody;
|
57
|
+
- (void)sendResponseBody;
|
58
|
+
- (void)sendResponseHeaders;
|
59
|
+
|
60
|
+
@end
|
61
|
+
|
62
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
63
|
+
#pragma mark -
|
64
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
65
|
+
|
66
|
+
@implementation WebSocket
|
67
|
+
{
|
68
|
+
BOOL isRFC6455;
|
69
|
+
BOOL nextFrameMasked;
|
70
|
+
NSUInteger nextOpCode;
|
71
|
+
NSData *maskingKey;
|
72
|
+
}
|
73
|
+
|
74
|
+
+ (BOOL)isWebSocketRequest:(HTTPMessage *)request
|
75
|
+
{
|
76
|
+
// Request (Draft 75):
|
77
|
+
//
|
78
|
+
// GET /demo HTTP/1.1
|
79
|
+
// Upgrade: WebSocket
|
80
|
+
// Connection: Upgrade
|
81
|
+
// Host: example.com
|
82
|
+
// Origin: http://example.com
|
83
|
+
// WebSocket-Protocol: sample
|
84
|
+
//
|
85
|
+
//
|
86
|
+
// Request (Draft 76):
|
87
|
+
//
|
88
|
+
// GET /demo HTTP/1.1
|
89
|
+
// Upgrade: WebSocket
|
90
|
+
// Connection: Upgrade
|
91
|
+
// Host: example.com
|
92
|
+
// Origin: http://example.com
|
93
|
+
// Sec-WebSocket-Protocol: sample
|
94
|
+
// Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5
|
95
|
+
// Sec-WebSocket-Key2: 12998 5 Y3 1 .P00
|
96
|
+
//
|
97
|
+
// ^n:ds[4U
|
98
|
+
|
99
|
+
// Look for Upgrade: and Connection: headers.
|
100
|
+
// If we find them, and they have the proper value,
|
101
|
+
// we can safely assume this is a websocket request.
|
102
|
+
|
103
|
+
NSString *upgradeHeaderValue = [request headerField:@"Upgrade"];
|
104
|
+
NSString *connectionHeaderValue = [request headerField:@"Connection"];
|
105
|
+
|
106
|
+
BOOL isWebSocket = YES;
|
107
|
+
|
108
|
+
if (!upgradeHeaderValue || !connectionHeaderValue) {
|
109
|
+
isWebSocket = NO;
|
110
|
+
}
|
111
|
+
else if (![upgradeHeaderValue caseInsensitiveCompare:@"WebSocket"] == NSOrderedSame) {
|
112
|
+
isWebSocket = NO;
|
113
|
+
}
|
114
|
+
else if ([connectionHeaderValue rangeOfString:@"Upgrade" options:NSCaseInsensitiveSearch].location == NSNotFound) {
|
115
|
+
isWebSocket = NO;
|
116
|
+
}
|
117
|
+
|
118
|
+
HTTPLogTrace2(@"%@: %@ - %@", THIS_FILE, THIS_METHOD, (isWebSocket ? @"YES" : @"NO"));
|
119
|
+
|
120
|
+
return isWebSocket;
|
121
|
+
}
|
122
|
+
|
123
|
+
+ (BOOL)isVersion76Request:(HTTPMessage *)request
|
124
|
+
{
|
125
|
+
NSString *key1 = [request headerField:@"Sec-WebSocket-Key1"];
|
126
|
+
NSString *key2 = [request headerField:@"Sec-WebSocket-Key2"];
|
127
|
+
|
128
|
+
BOOL isVersion76;
|
129
|
+
|
130
|
+
if (!key1 || !key2) {
|
131
|
+
isVersion76 = NO;
|
132
|
+
}
|
133
|
+
else {
|
134
|
+
isVersion76 = YES;
|
135
|
+
}
|
136
|
+
|
137
|
+
HTTPLogTrace2(@"%@: %@ - %@", THIS_FILE, THIS_METHOD, (isVersion76 ? @"YES" : @"NO"));
|
138
|
+
|
139
|
+
return isVersion76;
|
140
|
+
}
|
141
|
+
|
142
|
+
+ (BOOL)isRFC6455Request:(HTTPMessage *)request
|
143
|
+
{
|
144
|
+
NSString *key = [request headerField:@"Sec-WebSocket-Key"];
|
145
|
+
BOOL isRFC6455 = (key != nil);
|
146
|
+
|
147
|
+
HTTPLogTrace2(@"%@: %@ - %@", THIS_FILE, THIS_METHOD, (isRFC6455 ? @"YES" : @"NO"));
|
148
|
+
|
149
|
+
return isRFC6455;
|
150
|
+
}
|
151
|
+
|
152
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
153
|
+
#pragma mark Setup and Teardown
|
154
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
155
|
+
|
156
|
+
@synthesize websocketQueue;
|
157
|
+
|
158
|
+
- (id)initWithRequest:(HTTPMessage *)aRequest socket:(GCDAsyncSocket *)socket
|
159
|
+
{
|
160
|
+
HTTPLogTrace();
|
161
|
+
|
162
|
+
if (aRequest == nil)
|
163
|
+
{
|
164
|
+
return nil;
|
165
|
+
}
|
166
|
+
|
167
|
+
if ((self = [super init]))
|
168
|
+
{
|
169
|
+
if (HTTP_LOG_VERBOSE)
|
170
|
+
{
|
171
|
+
NSData *requestHeaders = [aRequest messageData];
|
172
|
+
|
173
|
+
NSString *temp = [[NSString alloc] initWithData:requestHeaders encoding:NSUTF8StringEncoding];
|
174
|
+
HTTPLogVerbose(@"%@[%p] Request Headers:\n%@", THIS_FILE, self, temp);
|
175
|
+
}
|
176
|
+
|
177
|
+
websocketQueue = dispatch_queue_create("WebSocket", NULL);
|
178
|
+
request = aRequest;
|
179
|
+
|
180
|
+
asyncSocket = socket;
|
181
|
+
[asyncSocket setDelegate:self delegateQueue:websocketQueue];
|
182
|
+
|
183
|
+
isOpen = NO;
|
184
|
+
isVersion76 = [[self class] isVersion76Request:request];
|
185
|
+
isRFC6455 = [[self class] isRFC6455Request:request];
|
186
|
+
|
187
|
+
term = [[NSData alloc] initWithBytes:"\xFF" length:1];
|
188
|
+
}
|
189
|
+
return self;
|
190
|
+
}
|
191
|
+
|
192
|
+
- (void)dealloc
|
193
|
+
{
|
194
|
+
HTTPLogTrace();
|
195
|
+
|
196
|
+
#if !OS_OBJECT_USE_OBJC
|
197
|
+
dispatch_release(websocketQueue);
|
198
|
+
#endif
|
199
|
+
|
200
|
+
[asyncSocket setDelegate:nil delegateQueue:NULL];
|
201
|
+
[asyncSocket disconnect];
|
202
|
+
}
|
203
|
+
|
204
|
+
- (id)delegate
|
205
|
+
{
|
206
|
+
__block id result = nil;
|
207
|
+
|
208
|
+
dispatch_sync(websocketQueue, ^{
|
209
|
+
result = delegate;
|
210
|
+
});
|
211
|
+
|
212
|
+
return result;
|
213
|
+
}
|
214
|
+
|
215
|
+
- (void)setDelegate:(id)newDelegate
|
216
|
+
{
|
217
|
+
dispatch_async(websocketQueue, ^{
|
218
|
+
delegate = newDelegate;
|
219
|
+
});
|
220
|
+
}
|
221
|
+
|
222
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
223
|
+
#pragma mark Start and Stop
|
224
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
225
|
+
|
226
|
+
/**
|
227
|
+
* Starting point for the WebSocket after it has been fully initialized (including subclasses).
|
228
|
+
* This method is called by the HTTPConnection it is spawned from.
|
229
|
+
**/
|
230
|
+
- (void)start
|
231
|
+
{
|
232
|
+
// This method is not exactly designed to be overriden.
|
233
|
+
// Subclasses are encouraged to override the didOpen method instead.
|
234
|
+
|
235
|
+
dispatch_async(websocketQueue, ^{ @autoreleasepool {
|
236
|
+
|
237
|
+
if (isStarted) return;
|
238
|
+
isStarted = YES;
|
239
|
+
|
240
|
+
if (isVersion76)
|
241
|
+
{
|
242
|
+
[self readRequestBody];
|
243
|
+
}
|
244
|
+
else
|
245
|
+
{
|
246
|
+
[self sendResponseHeaders];
|
247
|
+
[self didOpen];
|
248
|
+
}
|
249
|
+
}});
|
250
|
+
}
|
251
|
+
|
252
|
+
/**
|
253
|
+
* This method is called by the HTTPServer if it is asked to stop.
|
254
|
+
* The server, in turn, invokes stop on each WebSocket instance.
|
255
|
+
**/
|
256
|
+
- (void)stop
|
257
|
+
{
|
258
|
+
// This method is not exactly designed to be overriden.
|
259
|
+
// Subclasses are encouraged to override the didClose method instead.
|
260
|
+
|
261
|
+
dispatch_async(websocketQueue, ^{ @autoreleasepool {
|
262
|
+
|
263
|
+
[asyncSocket disconnect];
|
264
|
+
}});
|
265
|
+
}
|
266
|
+
|
267
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
268
|
+
#pragma mark HTTP Response
|
269
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
270
|
+
|
271
|
+
- (void)readRequestBody
|
272
|
+
{
|
273
|
+
HTTPLogTrace();
|
274
|
+
|
275
|
+
NSAssert(isVersion76, @"WebSocket version 75 doesn't contain a request body");
|
276
|
+
|
277
|
+
[asyncSocket readDataToLength:8 withTimeout:TIMEOUT_NONE tag:TAG_HTTP_REQUEST_BODY];
|
278
|
+
}
|
279
|
+
|
280
|
+
- (NSString *)originResponseHeaderValue
|
281
|
+
{
|
282
|
+
HTTPLogTrace();
|
283
|
+
|
284
|
+
NSString *origin = [request headerField:@"Origin"];
|
285
|
+
|
286
|
+
if (origin == nil)
|
287
|
+
{
|
288
|
+
NSString *port = [NSString stringWithFormat:@"%hu", [asyncSocket localPort]];
|
289
|
+
|
290
|
+
return [NSString stringWithFormat:@"http://localhost:%@", port];
|
291
|
+
}
|
292
|
+
else
|
293
|
+
{
|
294
|
+
return origin;
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
- (NSString *)locationResponseHeaderValue
|
299
|
+
{
|
300
|
+
HTTPLogTrace();
|
301
|
+
|
302
|
+
NSString *location;
|
303
|
+
|
304
|
+
NSString *scheme = [asyncSocket isSecure] ? @"wss" : @"ws";
|
305
|
+
NSString *host = [request headerField:@"Host"];
|
306
|
+
|
307
|
+
NSString *requestUri = [[request url] relativeString];
|
308
|
+
|
309
|
+
if (host == nil)
|
310
|
+
{
|
311
|
+
NSString *port = [NSString stringWithFormat:@"%hu", [asyncSocket localPort]];
|
312
|
+
|
313
|
+
location = [NSString stringWithFormat:@"%@://localhost:%@%@", scheme, port, requestUri];
|
314
|
+
}
|
315
|
+
else
|
316
|
+
{
|
317
|
+
location = [NSString stringWithFormat:@"%@://%@%@", scheme, host, requestUri];
|
318
|
+
}
|
319
|
+
|
320
|
+
return location;
|
321
|
+
}
|
322
|
+
|
323
|
+
- (NSString *)secWebSocketKeyResponseHeaderValue {
|
324
|
+
NSString *key = [request headerField: @"Sec-WebSocket-Key"];
|
325
|
+
NSString *guid = @"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
326
|
+
return [[key stringByAppendingString: guid] dataUsingEncoding: NSUTF8StringEncoding].sha1Digest.base64Encoded;
|
327
|
+
}
|
328
|
+
|
329
|
+
- (void)sendResponseHeaders
|
330
|
+
{
|
331
|
+
HTTPLogTrace();
|
332
|
+
|
333
|
+
// Request (Draft 75):
|
334
|
+
//
|
335
|
+
// GET /demo HTTP/1.1
|
336
|
+
// Upgrade: WebSocket
|
337
|
+
// Connection: Upgrade
|
338
|
+
// Host: example.com
|
339
|
+
// Origin: http://example.com
|
340
|
+
// WebSocket-Protocol: sample
|
341
|
+
//
|
342
|
+
//
|
343
|
+
// Request (Draft 76):
|
344
|
+
//
|
345
|
+
// GET /demo HTTP/1.1
|
346
|
+
// Upgrade: WebSocket
|
347
|
+
// Connection: Upgrade
|
348
|
+
// Host: example.com
|
349
|
+
// Origin: http://example.com
|
350
|
+
// Sec-WebSocket-Protocol: sample
|
351
|
+
// Sec-WebSocket-Key2: 12998 5 Y3 1 .P00
|
352
|
+
// Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5
|
353
|
+
//
|
354
|
+
// ^n:ds[4U
|
355
|
+
|
356
|
+
|
357
|
+
// Response (Draft 75):
|
358
|
+
//
|
359
|
+
// HTTP/1.1 101 Web Socket Protocol Handshake
|
360
|
+
// Upgrade: WebSocket
|
361
|
+
// Connection: Upgrade
|
362
|
+
// WebSocket-Origin: http://example.com
|
363
|
+
// WebSocket-Location: ws://example.com/demo
|
364
|
+
// WebSocket-Protocol: sample
|
365
|
+
//
|
366
|
+
//
|
367
|
+
// Response (Draft 76):
|
368
|
+
//
|
369
|
+
// HTTP/1.1 101 WebSocket Protocol Handshake
|
370
|
+
// Upgrade: WebSocket
|
371
|
+
// Connection: Upgrade
|
372
|
+
// Sec-WebSocket-Origin: http://example.com
|
373
|
+
// Sec-WebSocket-Location: ws://example.com/demo
|
374
|
+
// Sec-WebSocket-Protocol: sample
|
375
|
+
//
|
376
|
+
// 8jKS'y:G*Co,Wxa-
|
377
|
+
|
378
|
+
|
379
|
+
HTTPMessage *wsResponse = [[HTTPMessage alloc] initResponseWithStatusCode:101
|
380
|
+
description:@"Web Socket Protocol Handshake"
|
381
|
+
version:HTTPVersion1_1];
|
382
|
+
|
383
|
+
[wsResponse setHeaderField:@"Upgrade" value:@"WebSocket"];
|
384
|
+
[wsResponse setHeaderField:@"Connection" value:@"Upgrade"];
|
385
|
+
|
386
|
+
// Note: It appears that WebSocket-Origin and WebSocket-Location
|
387
|
+
// are required for Google's Chrome implementation to work properly.
|
388
|
+
//
|
389
|
+
// If we don't send either header, Chrome will never report the WebSocket as open.
|
390
|
+
// If we only send one of the two, Chrome will immediately close the WebSocket.
|
391
|
+
//
|
392
|
+
// In addition to this it appears that Chrome's implementation is very picky of the values of the headers.
|
393
|
+
// They have to match exactly with what Chrome sent us or it will close the WebSocket.
|
394
|
+
|
395
|
+
NSString *originValue = [self originResponseHeaderValue];
|
396
|
+
NSString *locationValue = [self locationResponseHeaderValue];
|
397
|
+
|
398
|
+
NSString *originField = isVersion76 ? @"Sec-WebSocket-Origin" : @"WebSocket-Origin";
|
399
|
+
NSString *locationField = isVersion76 ? @"Sec-WebSocket-Location" : @"WebSocket-Location";
|
400
|
+
|
401
|
+
[wsResponse setHeaderField:originField value:originValue];
|
402
|
+
[wsResponse setHeaderField:locationField value:locationValue];
|
403
|
+
|
404
|
+
NSString *acceptValue = [self secWebSocketKeyResponseHeaderValue];
|
405
|
+
if (acceptValue) {
|
406
|
+
[wsResponse setHeaderField: @"Sec-WebSocket-Accept" value: acceptValue];
|
407
|
+
}
|
408
|
+
|
409
|
+
NSData *responseHeaders = [wsResponse messageData];
|
410
|
+
|
411
|
+
|
412
|
+
if (HTTP_LOG_VERBOSE)
|
413
|
+
{
|
414
|
+
NSString *temp = [[NSString alloc] initWithData:responseHeaders encoding:NSUTF8StringEncoding];
|
415
|
+
HTTPLogVerbose(@"%@[%p] Response Headers:\n%@", THIS_FILE, self, temp);
|
416
|
+
}
|
417
|
+
|
418
|
+
[asyncSocket writeData:responseHeaders withTimeout:TIMEOUT_NONE tag:TAG_HTTP_RESPONSE_HEADERS];
|
419
|
+
}
|
420
|
+
|
421
|
+
- (NSData *)processKey:(NSString *)key
|
422
|
+
{
|
423
|
+
HTTPLogTrace();
|
424
|
+
|
425
|
+
unichar c;
|
426
|
+
NSUInteger i;
|
427
|
+
NSUInteger length = [key length];
|
428
|
+
|
429
|
+
// Concatenate the digits into a string,
|
430
|
+
// and count the number of spaces.
|
431
|
+
|
432
|
+
NSMutableString *numStr = [NSMutableString stringWithCapacity:10];
|
433
|
+
long long numSpaces = 0;
|
434
|
+
|
435
|
+
for (i = 0; i < length; i++)
|
436
|
+
{
|
437
|
+
c = [key characterAtIndex:i];
|
438
|
+
|
439
|
+
if (c >= '0' && c <= '9')
|
440
|
+
{
|
441
|
+
[numStr appendFormat:@"%C", c];
|
442
|
+
}
|
443
|
+
else if (c == ' ')
|
444
|
+
{
|
445
|
+
numSpaces++;
|
446
|
+
}
|
447
|
+
}
|
448
|
+
|
449
|
+
long long num = strtoll([numStr UTF8String], NULL, 10);
|
450
|
+
|
451
|
+
long long resultHostNum;
|
452
|
+
|
453
|
+
if (numSpaces == 0)
|
454
|
+
resultHostNum = 0;
|
455
|
+
else
|
456
|
+
resultHostNum = num / numSpaces;
|
457
|
+
|
458
|
+
HTTPLogVerbose(@"key(%@) -> %qi / %qi = %qi", key, num, numSpaces, resultHostNum);
|
459
|
+
|
460
|
+
// Convert result to 4 byte big-endian (network byte order)
|
461
|
+
// and then convert to raw data.
|
462
|
+
|
463
|
+
UInt32 result = OSSwapHostToBigInt32((uint32_t)resultHostNum);
|
464
|
+
|
465
|
+
return [NSData dataWithBytes:&result length:4];
|
466
|
+
}
|
467
|
+
|
468
|
+
- (void)sendResponseBody:(NSData *)d3
|
469
|
+
{
|
470
|
+
HTTPLogTrace();
|
471
|
+
|
472
|
+
NSAssert(isVersion76, @"WebSocket version 75 doesn't contain a response body");
|
473
|
+
NSAssert([d3 length] == 8, @"Invalid requestBody length");
|
474
|
+
|
475
|
+
NSString *key1 = [request headerField:@"Sec-WebSocket-Key1"];
|
476
|
+
NSString *key2 = [request headerField:@"Sec-WebSocket-Key2"];
|
477
|
+
|
478
|
+
NSData *d1 = [self processKey:key1];
|
479
|
+
NSData *d2 = [self processKey:key2];
|
480
|
+
|
481
|
+
// Concatenated d1, d2 & d3
|
482
|
+
|
483
|
+
NSMutableData *d0 = [NSMutableData dataWithCapacity:(4+4+8)];
|
484
|
+
[d0 appendData:d1];
|
485
|
+
[d0 appendData:d2];
|
486
|
+
[d0 appendData:d3];
|
487
|
+
|
488
|
+
// Hash the data using MD5
|
489
|
+
|
490
|
+
NSData *responseBody = [d0 md5Digest];
|
491
|
+
|
492
|
+
[asyncSocket writeData:responseBody withTimeout:TIMEOUT_NONE tag:TAG_HTTP_RESPONSE_BODY];
|
493
|
+
|
494
|
+
if (HTTP_LOG_VERBOSE)
|
495
|
+
{
|
496
|
+
NSString *s1 = [[NSString alloc] initWithData:d1 encoding:NSASCIIStringEncoding];
|
497
|
+
NSString *s2 = [[NSString alloc] initWithData:d2 encoding:NSASCIIStringEncoding];
|
498
|
+
NSString *s3 = [[NSString alloc] initWithData:d3 encoding:NSASCIIStringEncoding];
|
499
|
+
|
500
|
+
NSString *s0 = [[NSString alloc] initWithData:d0 encoding:NSASCIIStringEncoding];
|
501
|
+
|
502
|
+
NSString *sH = [[NSString alloc] initWithData:responseBody encoding:NSASCIIStringEncoding];
|
503
|
+
|
504
|
+
HTTPLogVerbose(@"key1 result : raw(%@) str(%@)", d1, s1);
|
505
|
+
HTTPLogVerbose(@"key2 result : raw(%@) str(%@)", d2, s2);
|
506
|
+
HTTPLogVerbose(@"key3 passed : raw(%@) str(%@)", d3, s3);
|
507
|
+
HTTPLogVerbose(@"key0 concat : raw(%@) str(%@)", d0, s0);
|
508
|
+
HTTPLogVerbose(@"responseBody: raw(%@) str(%@)", responseBody, sH);
|
509
|
+
|
510
|
+
}
|
511
|
+
}
|
512
|
+
|
513
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
514
|
+
#pragma mark Core Functionality
|
515
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
516
|
+
|
517
|
+
- (void)didOpen
|
518
|
+
{
|
519
|
+
HTTPLogTrace();
|
520
|
+
|
521
|
+
// Override me to perform any custom actions once the WebSocket has been opened.
|
522
|
+
// This method is invoked on the websocketQueue.
|
523
|
+
//
|
524
|
+
// Don't forget to invoke [super didOpen] in your method.
|
525
|
+
|
526
|
+
// Start reading for messages
|
527
|
+
[asyncSocket readDataToLength:1 withTimeout:TIMEOUT_NONE tag:(isRFC6455 ? TAG_PAYLOAD_PREFIX : TAG_PREFIX)];
|
528
|
+
|
529
|
+
// Notify delegate
|
530
|
+
if ([delegate respondsToSelector:@selector(webSocketDidOpen:)])
|
531
|
+
{
|
532
|
+
[delegate webSocketDidOpen:self];
|
533
|
+
}
|
534
|
+
}
|
535
|
+
|
536
|
+
- (void)sendMessage:(NSString *)msg
|
537
|
+
{
|
538
|
+
NSData *msgData = [msg dataUsingEncoding:NSUTF8StringEncoding];
|
539
|
+
[self sendData:msgData];
|
540
|
+
}
|
541
|
+
|
542
|
+
- (void)sendData:(NSData *)msgData
|
543
|
+
{
|
544
|
+
HTTPLogTrace();
|
545
|
+
|
546
|
+
NSMutableData *data = nil;
|
547
|
+
|
548
|
+
if (isRFC6455)
|
549
|
+
{
|
550
|
+
NSUInteger length = msgData.length;
|
551
|
+
if (length <= 125)
|
552
|
+
{
|
553
|
+
data = [NSMutableData dataWithCapacity:(length + 2)];
|
554
|
+
[data appendBytes: "\x81" length:1];
|
555
|
+
UInt8 len = (UInt8)length;
|
556
|
+
[data appendBytes: &len length:1];
|
557
|
+
[data appendData:msgData];
|
558
|
+
}
|
559
|
+
else if (length <= 0xFFFF)
|
560
|
+
{
|
561
|
+
data = [NSMutableData dataWithCapacity:(length + 4)];
|
562
|
+
[data appendBytes: "\x81\x7E" length:2];
|
563
|
+
UInt16 len = (UInt16)length;
|
564
|
+
[data appendBytes: (UInt8[]){len >> 8, len & 0xFF} length:2];
|
565
|
+
[data appendData:msgData];
|
566
|
+
}
|
567
|
+
else
|
568
|
+
{
|
569
|
+
data = [NSMutableData dataWithCapacity:(length + 10)];
|
570
|
+
[data appendBytes: "\x81\x7F" length:2];
|
571
|
+
[data appendBytes: (UInt8[]){0, 0, 0, 0, (UInt8)(length >> 24), (UInt8)(length >> 16), (UInt8)(length >> 8), length & 0xFF} length:8];
|
572
|
+
[data appendData:msgData];
|
573
|
+
}
|
574
|
+
}
|
575
|
+
else
|
576
|
+
{
|
577
|
+
data = [NSMutableData dataWithCapacity:([msgData length] + 2)];
|
578
|
+
|
579
|
+
[data appendBytes:"\x00" length:1];
|
580
|
+
[data appendData:msgData];
|
581
|
+
[data appendBytes:"\xFF" length:1];
|
582
|
+
}
|
583
|
+
|
584
|
+
// Remember: GCDAsyncSocket is thread-safe
|
585
|
+
|
586
|
+
[asyncSocket writeData:data withTimeout:TIMEOUT_NONE tag:0];
|
587
|
+
}
|
588
|
+
|
589
|
+
- (void)didReceiveMessage:(NSString *)msg
|
590
|
+
{
|
591
|
+
HTTPLogTrace();
|
592
|
+
|
593
|
+
// Override me to process incoming messages.
|
594
|
+
// This method is invoked on the websocketQueue.
|
595
|
+
//
|
596
|
+
// For completeness, you should invoke [super didReceiveMessage:msg] in your method.
|
597
|
+
|
598
|
+
// Notify delegate
|
599
|
+
if ([delegate respondsToSelector:@selector(webSocket:didReceiveMessage:)])
|
600
|
+
{
|
601
|
+
[delegate webSocket:self didReceiveMessage:msg];
|
602
|
+
}
|
603
|
+
}
|
604
|
+
|
605
|
+
- (void)didClose
|
606
|
+
{
|
607
|
+
HTTPLogTrace();
|
608
|
+
|
609
|
+
// Override me to perform any cleanup when the socket is closed
|
610
|
+
// This method is invoked on the websocketQueue.
|
611
|
+
//
|
612
|
+
// Don't forget to invoke [super didClose] at the end of your method.
|
613
|
+
|
614
|
+
// Notify delegate
|
615
|
+
if ([delegate respondsToSelector:@selector(webSocketDidClose:)])
|
616
|
+
{
|
617
|
+
[delegate webSocketDidClose:self];
|
618
|
+
}
|
619
|
+
|
620
|
+
// Notify HTTPServer
|
621
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:WebSocketDidDieNotification object:self];
|
622
|
+
}
|
623
|
+
|
624
|
+
#pragma mark WebSocket Frame
|
625
|
+
|
626
|
+
- (BOOL)isValidWebSocketFrame:(UInt8)frame
|
627
|
+
{
|
628
|
+
NSUInteger rsv = frame & 0x70;
|
629
|
+
NSUInteger opcode = frame & 0x0F;
|
630
|
+
if (rsv || (3 <= opcode && opcode <= 7) || (0xB <= opcode && opcode <= 0xF))
|
631
|
+
{
|
632
|
+
return NO;
|
633
|
+
}
|
634
|
+
return YES;
|
635
|
+
}
|
636
|
+
|
637
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
638
|
+
#pragma mark AsyncSocket Delegate
|
639
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
640
|
+
|
641
|
+
// 0 1 2 3
|
642
|
+
// 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
|
643
|
+
// +-+-+-+-+-------+-+-------------+-------------------------------+
|
644
|
+
// |F|R|R|R| opcode|M| Payload len | Extended payload length |
|
645
|
+
// |I|S|S|S| (4) |A| (7) | (16/64) |
|
646
|
+
// |N|V|V|V| |S| | (if payload len==126/127) |
|
647
|
+
// | |1|2|3| |K| | |
|
648
|
+
// +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
|
649
|
+
// | Extended payload length continued, if payload len == 127 |
|
650
|
+
// + - - - - - - - - - - - - - - - +-------------------------------+
|
651
|
+
// | |Masking-key, if MASK set to 1 |
|
652
|
+
// +-------------------------------+-------------------------------+
|
653
|
+
// | Masking-key (continued) | Payload Data |
|
654
|
+
// +-------------------------------- - - - - - - - - - - - - - - - +
|
655
|
+
// : Payload Data continued ... :
|
656
|
+
// + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
|
657
|
+
// | Payload Data continued ... |
|
658
|
+
// +---------------------------------------------------------------+
|
659
|
+
|
660
|
+
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
|
661
|
+
{
|
662
|
+
HTTPLogTrace();
|
663
|
+
|
664
|
+
if (tag == TAG_HTTP_REQUEST_BODY)
|
665
|
+
{
|
666
|
+
[self sendResponseHeaders];
|
667
|
+
[self sendResponseBody:data];
|
668
|
+
[self didOpen];
|
669
|
+
}
|
670
|
+
else if (tag == TAG_PREFIX)
|
671
|
+
{
|
672
|
+
UInt8 *pFrame = (UInt8 *)[data bytes];
|
673
|
+
UInt8 frame = *pFrame;
|
674
|
+
|
675
|
+
if (frame <= 0x7F)
|
676
|
+
{
|
677
|
+
[asyncSocket readDataToData:term withTimeout:TIMEOUT_NONE tag:TAG_MSG_PLUS_SUFFIX];
|
678
|
+
}
|
679
|
+
else
|
680
|
+
{
|
681
|
+
// Unsupported frame type
|
682
|
+
[self didClose];
|
683
|
+
}
|
684
|
+
}
|
685
|
+
else if (tag == TAG_PAYLOAD_PREFIX)
|
686
|
+
{
|
687
|
+
UInt8 *pFrame = (UInt8 *)[data bytes];
|
688
|
+
UInt8 frame = *pFrame;
|
689
|
+
|
690
|
+
if ([self isValidWebSocketFrame: frame])
|
691
|
+
{
|
692
|
+
nextOpCode = (frame & 0x0F);
|
693
|
+
[asyncSocket readDataToLength:1 withTimeout:TIMEOUT_NONE tag:TAG_PAYLOAD_LENGTH];
|
694
|
+
}
|
695
|
+
else
|
696
|
+
{
|
697
|
+
// Unsupported frame type
|
698
|
+
[self didClose];
|
699
|
+
}
|
700
|
+
}
|
701
|
+
else if (tag == TAG_PAYLOAD_LENGTH)
|
702
|
+
{
|
703
|
+
UInt8 frame = *(UInt8 *)[data bytes];
|
704
|
+
BOOL masked = WS_PAYLOAD_IS_MASKED(frame);
|
705
|
+
NSUInteger length = WS_PAYLOAD_LENGTH(frame);
|
706
|
+
nextFrameMasked = masked;
|
707
|
+
maskingKey = nil;
|
708
|
+
if (length <= 125)
|
709
|
+
{
|
710
|
+
if (nextFrameMasked)
|
711
|
+
{
|
712
|
+
[asyncSocket readDataToLength:4 withTimeout:TIMEOUT_NONE tag:TAG_MSG_MASKING_KEY];
|
713
|
+
}
|
714
|
+
[asyncSocket readDataToLength:length withTimeout:TIMEOUT_NONE tag:TAG_MSG_WITH_LENGTH];
|
715
|
+
}
|
716
|
+
else if (length == 126)
|
717
|
+
{
|
718
|
+
[asyncSocket readDataToLength:2 withTimeout:TIMEOUT_NONE tag:TAG_PAYLOAD_LENGTH16];
|
719
|
+
}
|
720
|
+
else
|
721
|
+
{
|
722
|
+
[asyncSocket readDataToLength:8 withTimeout:TIMEOUT_NONE tag:TAG_PAYLOAD_LENGTH64];
|
723
|
+
}
|
724
|
+
}
|
725
|
+
else if (tag == TAG_PAYLOAD_LENGTH16)
|
726
|
+
{
|
727
|
+
UInt8 *pFrame = (UInt8 *)[data bytes];
|
728
|
+
NSUInteger length = ((NSUInteger)pFrame[0] << 8) | (NSUInteger)pFrame[1];
|
729
|
+
if (nextFrameMasked) {
|
730
|
+
[asyncSocket readDataToLength:4 withTimeout:TIMEOUT_NONE tag:TAG_MSG_MASKING_KEY];
|
731
|
+
}
|
732
|
+
[asyncSocket readDataToLength:length withTimeout:TIMEOUT_NONE tag:TAG_MSG_WITH_LENGTH];
|
733
|
+
}
|
734
|
+
else if (tag == TAG_PAYLOAD_LENGTH64)
|
735
|
+
{
|
736
|
+
// FIXME: 64bit data size in memory?
|
737
|
+
[self didClose];
|
738
|
+
}
|
739
|
+
else if (tag == TAG_MSG_WITH_LENGTH)
|
740
|
+
{
|
741
|
+
NSUInteger msgLength = [data length];
|
742
|
+
if (nextFrameMasked && maskingKey) {
|
743
|
+
NSMutableData *masked = data.mutableCopy;
|
744
|
+
UInt8 *pData = (UInt8 *)masked.mutableBytes;
|
745
|
+
UInt8 *pMask = (UInt8 *)maskingKey.bytes;
|
746
|
+
for (NSUInteger i = 0; i < msgLength; i++)
|
747
|
+
{
|
748
|
+
pData[i] = pData[i] ^ pMask[i % 4];
|
749
|
+
}
|
750
|
+
data = masked;
|
751
|
+
}
|
752
|
+
if (nextOpCode == WS_OP_TEXT_FRAME)
|
753
|
+
{
|
754
|
+
NSString *msg = [[NSString alloc] initWithBytes:[data bytes] length:msgLength encoding:NSUTF8StringEncoding];
|
755
|
+
[self didReceiveMessage:msg];
|
756
|
+
}
|
757
|
+
else
|
758
|
+
{
|
759
|
+
[self didClose];
|
760
|
+
return;
|
761
|
+
}
|
762
|
+
|
763
|
+
// Read next frame
|
764
|
+
[asyncSocket readDataToLength:1 withTimeout:TIMEOUT_NONE tag:TAG_PAYLOAD_PREFIX];
|
765
|
+
}
|
766
|
+
else if (tag == TAG_MSG_MASKING_KEY)
|
767
|
+
{
|
768
|
+
maskingKey = data.copy;
|
769
|
+
}
|
770
|
+
else
|
771
|
+
{
|
772
|
+
NSUInteger msgLength = [data length] - 1; // Excluding ending 0xFF frame
|
773
|
+
|
774
|
+
NSString *msg = [[NSString alloc] initWithBytes:[data bytes] length:msgLength encoding:NSUTF8StringEncoding];
|
775
|
+
|
776
|
+
[self didReceiveMessage:msg];
|
777
|
+
|
778
|
+
|
779
|
+
// Read next message
|
780
|
+
[asyncSocket readDataToLength:1 withTimeout:TIMEOUT_NONE tag:TAG_PREFIX];
|
781
|
+
}
|
782
|
+
}
|
783
|
+
|
784
|
+
- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)error
|
785
|
+
{
|
786
|
+
HTTPLogTrace2(@"%@[%p]: socketDidDisconnect:withError: %@", THIS_FILE, self, error);
|
787
|
+
|
788
|
+
[self didClose];
|
789
|
+
}
|
790
|
+
|
791
|
+
@end
|