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,33 @@
|
|
1
|
+
//
|
2
|
+
// MultipartMessagePart.h
|
3
|
+
// HttpServer
|
4
|
+
//
|
5
|
+
// Created by Валерий Гаврилов on 29.03.12.
|
6
|
+
// Copyright (c) 2012 LLC "Online Publishing Partners" (onlinepp.ru). All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#import <Foundation/Foundation.h>
|
10
|
+
|
11
|
+
|
12
|
+
//-----------------------------------------------------------------
|
13
|
+
// interface MultipartMessageHeader
|
14
|
+
//-----------------------------------------------------------------
|
15
|
+
enum {
|
16
|
+
contentTransferEncoding_unknown,
|
17
|
+
contentTransferEncoding_7bit,
|
18
|
+
contentTransferEncoding_8bit,
|
19
|
+
contentTransferEncoding_binary,
|
20
|
+
contentTransferEncoding_base64,
|
21
|
+
contentTransferEncoding_quotedPrintable,
|
22
|
+
};
|
23
|
+
|
24
|
+
@interface MultipartMessageHeader : NSObject {
|
25
|
+
NSMutableDictionary* fields;
|
26
|
+
int encoding;
|
27
|
+
NSString* contentDispositionName;
|
28
|
+
}
|
29
|
+
@property (strong,readonly) NSDictionary* fields;
|
30
|
+
@property (readonly) int encoding;
|
31
|
+
|
32
|
+
- (id) initWithData:(NSData*) data formEncoding:(NSStringEncoding) encoding;
|
33
|
+
@end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
//
|
2
|
+
// MultipartMessagePart.m
|
3
|
+
// HttpServer
|
4
|
+
//
|
5
|
+
// Created by Валерий Гаврилов on 29.03.12.
|
6
|
+
// Copyright (c) 2012 LLC "Online Publishing Partners" (onlinepp.ru). All rights reserved.
|
7
|
+
|
8
|
+
#import "MultipartMessageHeader.h"
|
9
|
+
#import "MultipartMessageHeaderField.h"
|
10
|
+
|
11
|
+
#import "HTTPLogging.h"
|
12
|
+
|
13
|
+
//-----------------------------------------------------------------
|
14
|
+
#pragma mark log level
|
15
|
+
|
16
|
+
#ifdef DEBUG
|
17
|
+
static const int httpLogLevel = HTTP_LOG_LEVEL_WARN;
|
18
|
+
#else
|
19
|
+
static const int httpLogLevel = HTTP_LOG_LEVEL_WARN;
|
20
|
+
#endif
|
21
|
+
|
22
|
+
//-----------------------------------------------------------------
|
23
|
+
// implementation MultipartMessageHeader
|
24
|
+
//-----------------------------------------------------------------
|
25
|
+
|
26
|
+
|
27
|
+
@implementation MultipartMessageHeader
|
28
|
+
@synthesize fields,encoding;
|
29
|
+
|
30
|
+
|
31
|
+
- (id) initWithData:(NSData *)data formEncoding:(NSStringEncoding) formEncoding {
|
32
|
+
if( nil == (self = [super init]) ) {
|
33
|
+
return self;
|
34
|
+
}
|
35
|
+
|
36
|
+
fields = [[NSMutableDictionary alloc] initWithCapacity:1];
|
37
|
+
|
38
|
+
// In case encoding is not mentioned,
|
39
|
+
encoding = contentTransferEncoding_unknown;
|
40
|
+
|
41
|
+
char* bytes = (char*)data.bytes;
|
42
|
+
NSUInteger length = data.length;
|
43
|
+
int offset = 0;
|
44
|
+
|
45
|
+
// split header into header fields, separated by \r\n
|
46
|
+
uint16_t fields_separator = 0x0A0D; // \r\n
|
47
|
+
while( offset < length - 2 ) {
|
48
|
+
|
49
|
+
// the !isspace condition is to support header unfolding
|
50
|
+
if( (*(uint16_t*) (bytes+offset) == fields_separator) && ((offset == length - 2) || !(isspace(bytes[offset+2])) )) {
|
51
|
+
NSData* fieldData = [NSData dataWithBytesNoCopy:bytes length:offset freeWhenDone:NO];
|
52
|
+
MultipartMessageHeaderField* field = [[MultipartMessageHeaderField alloc] initWithData: fieldData contentEncoding:formEncoding];
|
53
|
+
if( field ) {
|
54
|
+
[fields setObject:field forKey:field.name];
|
55
|
+
HTTPLogVerbose(@"MultipartFormDataParser: Processed Header field '%@'",field.name);
|
56
|
+
}
|
57
|
+
else {
|
58
|
+
NSString* fieldStr = [[NSString alloc] initWithData:fieldData encoding:NSASCIIStringEncoding];
|
59
|
+
HTTPLogWarn(@"MultipartFormDataParser: Failed to parse MIME header field. Input ASCII string:%@",fieldStr);
|
60
|
+
}
|
61
|
+
|
62
|
+
// move to the next header field
|
63
|
+
bytes += offset + 2;
|
64
|
+
length -= offset + 2;
|
65
|
+
offset = 0;
|
66
|
+
continue;
|
67
|
+
}
|
68
|
+
++ offset;
|
69
|
+
}
|
70
|
+
|
71
|
+
if( !fields.count ) {
|
72
|
+
// it was an empty header.
|
73
|
+
// we have to set default values.
|
74
|
+
// default header.
|
75
|
+
[fields setObject:@"text/plain" forKey:@"Content-Type"];
|
76
|
+
}
|
77
|
+
|
78
|
+
return self;
|
79
|
+
}
|
80
|
+
|
81
|
+
- (NSString *)description {
|
82
|
+
return [NSString stringWithFormat:@"%@",fields];
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
@end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
#import <Foundation/Foundation.h>
|
3
|
+
|
4
|
+
//-----------------------------------------------------------------
|
5
|
+
// interface MultipartMessageHeaderField
|
6
|
+
//-----------------------------------------------------------------
|
7
|
+
|
8
|
+
@interface MultipartMessageHeaderField : NSObject {
|
9
|
+
NSString* name;
|
10
|
+
NSString* value;
|
11
|
+
NSMutableDictionary* params;
|
12
|
+
}
|
13
|
+
|
14
|
+
@property (strong, readonly) NSString* value;
|
15
|
+
@property (strong, readonly) NSDictionary* params;
|
16
|
+
@property (strong, readonly) NSString* name;
|
17
|
+
|
18
|
+
//- (id) initWithLine:(NSString*) line;
|
19
|
+
//- (id) initWithName:(NSString*) paramName value:(NSString*) paramValue;
|
20
|
+
|
21
|
+
- (id) initWithData:(NSData*) data contentEncoding:(NSStringEncoding) encoding;
|
22
|
+
|
23
|
+
@end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
|
2
|
+
#import "MultipartMessageHeaderField.h"
|
3
|
+
#import "HTTPLogging.h"
|
4
|
+
|
5
|
+
//-----------------------------------------------------------------
|
6
|
+
#pragma mark log level
|
7
|
+
|
8
|
+
#ifdef DEBUG
|
9
|
+
static const int httpLogLevel = HTTP_LOG_LEVEL_WARN;
|
10
|
+
#else
|
11
|
+
static const int httpLogLevel = HTTP_LOG_LEVEL_WARN;
|
12
|
+
#endif
|
13
|
+
|
14
|
+
|
15
|
+
// helpers
|
16
|
+
int findChar(const char* str,NSUInteger length, char c);
|
17
|
+
NSString* extractParamValue(const char* bytes, NSUInteger length, NSStringEncoding encoding);
|
18
|
+
|
19
|
+
//-----------------------------------------------------------------
|
20
|
+
// interface MultipartMessageHeaderField (private)
|
21
|
+
//-----------------------------------------------------------------
|
22
|
+
|
23
|
+
|
24
|
+
@interface MultipartMessageHeaderField (private)
|
25
|
+
-(BOOL) parseHeaderValueBytes:(char*) bytes length:(NSUInteger) length encoding:(NSStringEncoding) encoding;
|
26
|
+
@end
|
27
|
+
|
28
|
+
|
29
|
+
//-----------------------------------------------------------------
|
30
|
+
// implementation MultipartMessageHeaderField
|
31
|
+
//-----------------------------------------------------------------
|
32
|
+
|
33
|
+
@implementation MultipartMessageHeaderField
|
34
|
+
@synthesize name,value,params;
|
35
|
+
|
36
|
+
- (id) initWithData:(NSData *)data contentEncoding:(NSStringEncoding)encoding {
|
37
|
+
params = [[NSMutableDictionary alloc] initWithCapacity:1];
|
38
|
+
|
39
|
+
char* bytes = (char*)data.bytes;
|
40
|
+
NSUInteger length = data.length;
|
41
|
+
|
42
|
+
int separatorOffset = findChar(bytes, length, ':');
|
43
|
+
if( (-1 == separatorOffset) || (separatorOffset >= length-2) ) {
|
44
|
+
HTTPLogError(@"MultipartFormDataParser: Bad format.No colon in field header.");
|
45
|
+
// tear down
|
46
|
+
return nil;
|
47
|
+
}
|
48
|
+
|
49
|
+
// header name is always ascii encoded;
|
50
|
+
name = [[NSString alloc] initWithBytes: bytes length: separatorOffset encoding: NSASCIIStringEncoding];
|
51
|
+
if( nil == name ) {
|
52
|
+
HTTPLogError(@"MultipartFormDataParser: Bad MIME header name.");
|
53
|
+
// tear down
|
54
|
+
return nil;
|
55
|
+
}
|
56
|
+
|
57
|
+
// skip the separator and the next ' ' symbol
|
58
|
+
bytes += separatorOffset + 2;
|
59
|
+
length -= separatorOffset + 2;
|
60
|
+
|
61
|
+
separatorOffset = findChar(bytes, length, ';');
|
62
|
+
if( separatorOffset == -1 ) {
|
63
|
+
// couldn't find ';', means we don't have extra params here.
|
64
|
+
value = [[NSString alloc] initWithBytes:bytes length: length encoding:encoding];
|
65
|
+
|
66
|
+
if( nil == value ) {
|
67
|
+
HTTPLogError(@"MultipartFormDataParser: Bad MIME header value for header name: '%@'",name);
|
68
|
+
// tear down
|
69
|
+
return nil;
|
70
|
+
}
|
71
|
+
return self;
|
72
|
+
}
|
73
|
+
|
74
|
+
value = [[NSString alloc] initWithBytes:bytes length: separatorOffset encoding:encoding];
|
75
|
+
HTTPLogVerbose(@"MultipartFormDataParser: Processing header field '%@' : '%@'",name,value);
|
76
|
+
// skipe the separator and the next ' ' symbol
|
77
|
+
bytes += separatorOffset + 2;
|
78
|
+
length -= separatorOffset + 2;
|
79
|
+
|
80
|
+
// parse the "params" part of the header
|
81
|
+
if( ![self parseHeaderValueBytes:bytes length:length encoding:encoding] ) {
|
82
|
+
NSString* paramsStr = [[NSString alloc] initWithBytes:bytes length:length encoding:NSASCIIStringEncoding];
|
83
|
+
HTTPLogError(@"MultipartFormDataParser: Bad params for header with name '%@' and value '%@'",name,value);
|
84
|
+
HTTPLogError(@"MultipartFormDataParser: Params str: %@",paramsStr);
|
85
|
+
|
86
|
+
return nil;
|
87
|
+
}
|
88
|
+
return self;
|
89
|
+
}
|
90
|
+
|
91
|
+
-(BOOL) parseHeaderValueBytes:(char*) bytes length:(NSUInteger) length encoding:(NSStringEncoding) encoding {
|
92
|
+
int offset = 0;
|
93
|
+
NSString* currentParam = nil;
|
94
|
+
BOOL insideQuote = NO;
|
95
|
+
while( offset < length ) {
|
96
|
+
if( bytes[offset] == '\"' ) {
|
97
|
+
if( !offset || bytes[offset-1] != '\\' ) {
|
98
|
+
insideQuote = !insideQuote;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
// skip quoted symbols
|
103
|
+
if( insideQuote ) {
|
104
|
+
++ offset;
|
105
|
+
continue;
|
106
|
+
}
|
107
|
+
if( bytes[offset] == '=' ) {
|
108
|
+
if( currentParam ) {
|
109
|
+
// found '=' before terminating previous param.
|
110
|
+
return NO;
|
111
|
+
}
|
112
|
+
currentParam = [[NSString alloc] initWithBytes:bytes length:offset encoding:NSASCIIStringEncoding];
|
113
|
+
|
114
|
+
bytes+=offset + 1;
|
115
|
+
length -= offset + 1;
|
116
|
+
offset = 0;
|
117
|
+
continue;
|
118
|
+
}
|
119
|
+
if( bytes[offset] == ';' ) {
|
120
|
+
if( !currentParam ) {
|
121
|
+
// found ; before stating '='.
|
122
|
+
HTTPLogError(@"MultipartFormDataParser: Unexpected ';' when parsing header");
|
123
|
+
return NO;
|
124
|
+
}
|
125
|
+
NSString* paramValue = extractParamValue(bytes, offset,encoding);
|
126
|
+
if( nil == paramValue ) {
|
127
|
+
HTTPLogWarn(@"MultipartFormDataParser: Failed to exctract paramValue for key %@ in header %@",currentParam,name);
|
128
|
+
}
|
129
|
+
else {
|
130
|
+
#ifdef DEBUG
|
131
|
+
if( [params objectForKey:currentParam] ) {
|
132
|
+
HTTPLogWarn(@"MultipartFormDataParser: param %@ mentioned more then once in header %@",currentParam,name);
|
133
|
+
}
|
134
|
+
#endif
|
135
|
+
[params setObject:paramValue forKey:currentParam];
|
136
|
+
HTTPLogVerbose(@"MultipartFormDataParser: header param: %@ = %@",currentParam,paramValue);
|
137
|
+
}
|
138
|
+
|
139
|
+
currentParam = nil;
|
140
|
+
|
141
|
+
// ';' separator has ' ' following, skip them.
|
142
|
+
bytes+=offset + 2;
|
143
|
+
length -= offset + 2;
|
144
|
+
offset = 0;
|
145
|
+
}
|
146
|
+
++ offset;
|
147
|
+
}
|
148
|
+
|
149
|
+
// add last param
|
150
|
+
if( insideQuote ) {
|
151
|
+
HTTPLogWarn(@"MultipartFormDataParser: unterminated quote in header %@",name);
|
152
|
+
// return YES;
|
153
|
+
}
|
154
|
+
if( currentParam ) {
|
155
|
+
NSString* paramValue = extractParamValue(bytes, length, encoding);
|
156
|
+
|
157
|
+
if( nil == paramValue ) {
|
158
|
+
HTTPLogError(@"MultipartFormDataParser: Failed to exctract paramValue for key %@ in header %@",currentParam,name);
|
159
|
+
}
|
160
|
+
|
161
|
+
#ifdef DEBUG
|
162
|
+
if( [params objectForKey:currentParam] ) {
|
163
|
+
HTTPLogWarn(@"MultipartFormDataParser: param %@ mentioned more then once in one header",currentParam);
|
164
|
+
}
|
165
|
+
#endif
|
166
|
+
[params setObject:paramValue forKey:currentParam];
|
167
|
+
HTTPLogVerbose(@"MultipartFormDataParser: header param: %@ = %@",currentParam,paramValue);
|
168
|
+
currentParam = nil;
|
169
|
+
}
|
170
|
+
|
171
|
+
return YES;
|
172
|
+
}
|
173
|
+
|
174
|
+
- (NSString *)description {
|
175
|
+
return [NSString stringWithFormat:@"%@:%@\n params: %@",name,value,params];
|
176
|
+
}
|
177
|
+
|
178
|
+
@end
|
179
|
+
|
180
|
+
int findChar(const char* str, NSUInteger length, char c) {
|
181
|
+
int offset = 0;
|
182
|
+
while( offset < length ) {
|
183
|
+
if( str[offset] == c )
|
184
|
+
return offset;
|
185
|
+
++ offset;
|
186
|
+
}
|
187
|
+
return -1;
|
188
|
+
}
|
189
|
+
|
190
|
+
NSString* extractParamValue(const char* bytes, NSUInteger length, NSStringEncoding encoding) {
|
191
|
+
if( !length )
|
192
|
+
return nil;
|
193
|
+
NSMutableString* value = nil;
|
194
|
+
|
195
|
+
if( bytes[0] == '"' ) {
|
196
|
+
// values may be quoted. Strip the quotes to get what we need.
|
197
|
+
value = [[NSMutableString alloc] initWithBytes:bytes + 1 length: length - 2 encoding:encoding];
|
198
|
+
}
|
199
|
+
else {
|
200
|
+
value = [[NSMutableString alloc] initWithBytes:bytes length: length encoding:encoding];
|
201
|
+
}
|
202
|
+
// restore escaped symbols
|
203
|
+
NSRange range= [value rangeOfString:@"\\"];
|
204
|
+
while ( range.length ) {
|
205
|
+
[value deleteCharactersInRange:range];
|
206
|
+
range.location ++;
|
207
|
+
range = [value rangeOfString:@"\\" options:NSLiteralSearch range: range];
|
208
|
+
}
|
209
|
+
return value;
|
210
|
+
}
|
211
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#import <Foundation/Foundation.h>
|
2
|
+
#import "HTTPResponse.h"
|
3
|
+
|
4
|
+
@class HTTPConnection;
|
5
|
+
|
6
|
+
/**
|
7
|
+
* This is an asynchronous version of HTTPFileResponse.
|
8
|
+
* It reads data from the given file asynchronously via GCD.
|
9
|
+
*
|
10
|
+
* It may be overriden to allow custom post-processing of the data that has been read from the file.
|
11
|
+
* An example of this is the HTTPDynamicFileResponse class.
|
12
|
+
**/
|
13
|
+
|
14
|
+
@interface HTTPAsyncFileResponse : NSObject <HTTPResponse>
|
15
|
+
{
|
16
|
+
HTTPConnection *connection;
|
17
|
+
|
18
|
+
NSString *filePath;
|
19
|
+
UInt64 fileLength;
|
20
|
+
UInt64 fileOffset; // File offset as pertains to data given to connection
|
21
|
+
UInt64 readOffset; // File offset as pertains to data read from file (but maybe not returned to connection)
|
22
|
+
|
23
|
+
BOOL aborted;
|
24
|
+
|
25
|
+
NSData *data;
|
26
|
+
|
27
|
+
int fileFD;
|
28
|
+
void *readBuffer;
|
29
|
+
NSUInteger readBufferSize; // Malloced size of readBuffer
|
30
|
+
NSUInteger readBufferOffset; // Offset within readBuffer where the end of existing data is
|
31
|
+
NSUInteger readRequestLength;
|
32
|
+
dispatch_queue_t readQueue;
|
33
|
+
dispatch_source_t readSource;
|
34
|
+
BOOL readSourceSuspended;
|
35
|
+
}
|
36
|
+
|
37
|
+
- (id)initWithFilePath:(NSString *)filePath forConnection:(HTTPConnection *)connection;
|
38
|
+
- (NSString *)filePath;
|
39
|
+
|
40
|
+
@end
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Explanation of Variables (excluding those that are obvious)
|
44
|
+
*
|
45
|
+
* fileOffset
|
46
|
+
* This is the number of bytes that have been returned to the connection via the readDataOfLength method.
|
47
|
+
* If 1KB of data has been read from the file, but none of that data has yet been returned to the connection,
|
48
|
+
* then the fileOffset variable remains at zero.
|
49
|
+
* This variable is used in the calculation of the isDone method.
|
50
|
+
* Only after all data has been returned to the connection are we actually done.
|
51
|
+
*
|
52
|
+
* readOffset
|
53
|
+
* Represents the offset of the file descriptor.
|
54
|
+
* In other words, the file position indidcator for our read stream.
|
55
|
+
* It might be easy to think of it as the total number of bytes that have been read from the file.
|
56
|
+
* However, this isn't entirely accurate, as the setOffset: method may have caused us to
|
57
|
+
* jump ahead in the file (lseek).
|
58
|
+
*
|
59
|
+
* readBuffer
|
60
|
+
* Malloc'd buffer to hold data read from the file.
|
61
|
+
*
|
62
|
+
* readBufferSize
|
63
|
+
* Total allocation size of malloc'd buffer.
|
64
|
+
*
|
65
|
+
* readBufferOffset
|
66
|
+
* Represents the position in the readBuffer where we should store new bytes.
|
67
|
+
*
|
68
|
+
* readRequestLength
|
69
|
+
* The total number of bytes that were requested from the connection.
|
70
|
+
* It's OK if we return a lesser number of bytes to the connection.
|
71
|
+
* It's NOT OK if we return a greater number of bytes to the connection.
|
72
|
+
* Doing so would disrupt proper support for range requests.
|
73
|
+
* If, however, the response is chunked then we don't need to worry about this.
|
74
|
+
* Chunked responses inheritly don't support range requests.
|
75
|
+
**/
|
@@ -0,0 +1,405 @@
|
|
1
|
+
#import "HTTPAsyncFileResponse.h"
|
2
|
+
#import "HTTPConnection.h"
|
3
|
+
#import "HTTPLogging.h"
|
4
|
+
|
5
|
+
#import <unistd.h>
|
6
|
+
#import <fcntl.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 NULL_FD -1
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Architecure overview:
|
20
|
+
*
|
21
|
+
* HTTPConnection will invoke our readDataOfLength: method to fetch data.
|
22
|
+
* We will return nil, and then proceed to read the data via our readSource on our readQueue.
|
23
|
+
* Once the requested amount of data has been read, we then pause our readSource,
|
24
|
+
* and inform the connection of the available data.
|
25
|
+
*
|
26
|
+
* While our read is in progress, we don't have to worry about the connection calling any other methods,
|
27
|
+
* except the connectionDidClose method, which would be invoked if the remote end closed the socket connection.
|
28
|
+
* To safely handle this, we do a synchronous dispatch on the readQueue,
|
29
|
+
* and nilify the connection as well as cancel our readSource.
|
30
|
+
*
|
31
|
+
* In order to minimize resource consumption during a HEAD request,
|
32
|
+
* we don't open the file until we have to (until the connection starts requesting data).
|
33
|
+
**/
|
34
|
+
|
35
|
+
@implementation HTTPAsyncFileResponse
|
36
|
+
|
37
|
+
- (id)initWithFilePath:(NSString *)fpath forConnection:(HTTPConnection *)parent
|
38
|
+
{
|
39
|
+
if ((self = [super init]))
|
40
|
+
{
|
41
|
+
HTTPLogTrace();
|
42
|
+
|
43
|
+
connection = parent; // Parents retain children, children do NOT retain parents
|
44
|
+
|
45
|
+
fileFD = NULL_FD;
|
46
|
+
filePath = [fpath copy];
|
47
|
+
if (filePath == nil)
|
48
|
+
{
|
49
|
+
HTTPLogWarn(@"%@: Init failed - Nil filePath", THIS_FILE);
|
50
|
+
|
51
|
+
return nil;
|
52
|
+
}
|
53
|
+
|
54
|
+
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:NULL];
|
55
|
+
if (fileAttributes == nil)
|
56
|
+
{
|
57
|
+
HTTPLogWarn(@"%@: Init failed - Unable to get file attributes. filePath: %@", THIS_FILE, filePath);
|
58
|
+
|
59
|
+
return nil;
|
60
|
+
}
|
61
|
+
|
62
|
+
fileLength = (UInt64)[[fileAttributes objectForKey:NSFileSize] unsignedLongLongValue];
|
63
|
+
fileOffset = 0;
|
64
|
+
|
65
|
+
aborted = NO;
|
66
|
+
|
67
|
+
// We don't bother opening the file here.
|
68
|
+
// If this is a HEAD request we only need to know the fileLength.
|
69
|
+
}
|
70
|
+
return self;
|
71
|
+
}
|
72
|
+
|
73
|
+
- (void)abort
|
74
|
+
{
|
75
|
+
HTTPLogTrace();
|
76
|
+
|
77
|
+
[connection responseDidAbort:self];
|
78
|
+
aborted = YES;
|
79
|
+
}
|
80
|
+
|
81
|
+
- (void)processReadBuffer
|
82
|
+
{
|
83
|
+
// This method is here to allow superclasses to perform post-processing of the data.
|
84
|
+
// For an example, see the HTTPDynamicFileResponse class.
|
85
|
+
//
|
86
|
+
// At this point, the readBuffer has readBufferOffset bytes available.
|
87
|
+
// This method is in charge of updating the readBufferOffset.
|
88
|
+
// Failure to do so will cause the readBuffer to grow to fileLength. (Imagine a 1 GB file...)
|
89
|
+
|
90
|
+
// Copy the data out of the temporary readBuffer.
|
91
|
+
data = [[NSData alloc] initWithBytes:readBuffer length:readBufferOffset];
|
92
|
+
|
93
|
+
// Reset the read buffer.
|
94
|
+
readBufferOffset = 0;
|
95
|
+
|
96
|
+
// Notify the connection that we have data available for it.
|
97
|
+
[connection responseHasAvailableData:self];
|
98
|
+
}
|
99
|
+
|
100
|
+
- (void)pauseReadSource
|
101
|
+
{
|
102
|
+
if (!readSourceSuspended)
|
103
|
+
{
|
104
|
+
HTTPLogVerbose(@"%@[%p]: Suspending readSource", THIS_FILE, self);
|
105
|
+
|
106
|
+
readSourceSuspended = YES;
|
107
|
+
dispatch_suspend(readSource);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
- (void)resumeReadSource
|
112
|
+
{
|
113
|
+
if (readSourceSuspended)
|
114
|
+
{
|
115
|
+
HTTPLogVerbose(@"%@[%p]: Resuming readSource", THIS_FILE, self);
|
116
|
+
|
117
|
+
readSourceSuspended = NO;
|
118
|
+
dispatch_resume(readSource);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
- (void)cancelReadSource
|
123
|
+
{
|
124
|
+
HTTPLogVerbose(@"%@[%p]: Canceling readSource", THIS_FILE, self);
|
125
|
+
|
126
|
+
dispatch_source_cancel(readSource);
|
127
|
+
|
128
|
+
// Cancelling a dispatch source doesn't
|
129
|
+
// invoke the cancel handler if the dispatch source is paused.
|
130
|
+
|
131
|
+
if (readSourceSuspended)
|
132
|
+
{
|
133
|
+
readSourceSuspended = NO;
|
134
|
+
dispatch_resume(readSource);
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
- (BOOL)openFileAndSetupReadSource
|
139
|
+
{
|
140
|
+
HTTPLogTrace();
|
141
|
+
|
142
|
+
fileFD = open([filePath UTF8String], (O_RDONLY | O_NONBLOCK));
|
143
|
+
if (fileFD == NULL_FD)
|
144
|
+
{
|
145
|
+
HTTPLogError(@"%@: Unable to open file. filePath: %@", THIS_FILE, filePath);
|
146
|
+
|
147
|
+
return NO;
|
148
|
+
}
|
149
|
+
|
150
|
+
HTTPLogVerbose(@"%@[%p]: Open fd[%i] -> %@", THIS_FILE, self, fileFD, filePath);
|
151
|
+
|
152
|
+
readQueue = dispatch_queue_create("HTTPAsyncFileResponse", NULL);
|
153
|
+
readSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, fileFD, 0, readQueue);
|
154
|
+
|
155
|
+
|
156
|
+
dispatch_source_set_event_handler(readSource, ^{
|
157
|
+
|
158
|
+
HTTPLogTrace2(@"%@: eventBlock - fd[%i]", THIS_FILE, fileFD);
|
159
|
+
|
160
|
+
// Determine how much data we should read.
|
161
|
+
//
|
162
|
+
// It is OK if we ask to read more bytes than exist in the file.
|
163
|
+
// It is NOT OK to over-allocate the buffer.
|
164
|
+
|
165
|
+
unsigned long long _bytesAvailableOnFD = dispatch_source_get_data(readSource);
|
166
|
+
|
167
|
+
UInt64 _bytesLeftInFile = fileLength - readOffset;
|
168
|
+
|
169
|
+
NSUInteger bytesAvailableOnFD;
|
170
|
+
NSUInteger bytesLeftInFile;
|
171
|
+
|
172
|
+
bytesAvailableOnFD = (_bytesAvailableOnFD > NSUIntegerMax) ? NSUIntegerMax : (NSUInteger)_bytesAvailableOnFD;
|
173
|
+
bytesLeftInFile = (_bytesLeftInFile > NSUIntegerMax) ? NSUIntegerMax : (NSUInteger)_bytesLeftInFile;
|
174
|
+
|
175
|
+
NSUInteger bytesLeftInRequest = readRequestLength - readBufferOffset;
|
176
|
+
|
177
|
+
NSUInteger bytesLeft = MIN(bytesLeftInRequest, bytesLeftInFile);
|
178
|
+
|
179
|
+
NSUInteger bytesToRead = MIN(bytesAvailableOnFD, bytesLeft);
|
180
|
+
|
181
|
+
// Make sure buffer is big enough for read request.
|
182
|
+
// Do not over-allocate.
|
183
|
+
|
184
|
+
if (readBuffer == NULL || bytesToRead > (readBufferSize - readBufferOffset))
|
185
|
+
{
|
186
|
+
readBufferSize = bytesToRead;
|
187
|
+
readBuffer = reallocf(readBuffer, (size_t)bytesToRead);
|
188
|
+
|
189
|
+
if (readBuffer == NULL)
|
190
|
+
{
|
191
|
+
HTTPLogError(@"%@[%p]: Unable to allocate buffer", THIS_FILE, self);
|
192
|
+
|
193
|
+
[self pauseReadSource];
|
194
|
+
[self abort];
|
195
|
+
|
196
|
+
return;
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
// Perform the read
|
201
|
+
|
202
|
+
HTTPLogVerbose(@"%@[%p]: Attempting to read %lu bytes from file", THIS_FILE, self, (unsigned long)bytesToRead);
|
203
|
+
|
204
|
+
ssize_t result = read(fileFD, readBuffer + readBufferOffset, (size_t)bytesToRead);
|
205
|
+
|
206
|
+
// Check the results
|
207
|
+
if (result < 0)
|
208
|
+
{
|
209
|
+
HTTPLogError(@"%@: Error(%i) reading file(%@)", THIS_FILE, errno, filePath);
|
210
|
+
|
211
|
+
[self pauseReadSource];
|
212
|
+
[self abort];
|
213
|
+
}
|
214
|
+
else if (result == 0)
|
215
|
+
{
|
216
|
+
HTTPLogError(@"%@: Read EOF on file(%@)", THIS_FILE, filePath);
|
217
|
+
|
218
|
+
[self pauseReadSource];
|
219
|
+
[self abort];
|
220
|
+
}
|
221
|
+
else // (result > 0)
|
222
|
+
{
|
223
|
+
HTTPLogVerbose(@"%@[%p]: Read %lu bytes from file", THIS_FILE, self, (unsigned long)result);
|
224
|
+
|
225
|
+
readOffset += result;
|
226
|
+
readBufferOffset += result;
|
227
|
+
|
228
|
+
[self pauseReadSource];
|
229
|
+
[self processReadBuffer];
|
230
|
+
}
|
231
|
+
|
232
|
+
});
|
233
|
+
|
234
|
+
int theFileFD = fileFD;
|
235
|
+
#if !OS_OBJECT_USE_OBJC
|
236
|
+
dispatch_source_t theReadSource = readSource;
|
237
|
+
#endif
|
238
|
+
|
239
|
+
dispatch_source_set_cancel_handler(readSource, ^{
|
240
|
+
|
241
|
+
// Do not access self from within this block in any way, shape or form.
|
242
|
+
//
|
243
|
+
// Note: You access self if you reference an iVar.
|
244
|
+
|
245
|
+
HTTPLogTrace2(@"%@: cancelBlock - Close fd[%i]", THIS_FILE, theFileFD);
|
246
|
+
|
247
|
+
#if !OS_OBJECT_USE_OBJC
|
248
|
+
dispatch_release(theReadSource);
|
249
|
+
#endif
|
250
|
+
close(theFileFD);
|
251
|
+
});
|
252
|
+
|
253
|
+
readSourceSuspended = YES;
|
254
|
+
|
255
|
+
return YES;
|
256
|
+
}
|
257
|
+
|
258
|
+
- (BOOL)openFileIfNeeded
|
259
|
+
{
|
260
|
+
if (aborted)
|
261
|
+
{
|
262
|
+
// The file operation has been aborted.
|
263
|
+
// This could be because we failed to open the file,
|
264
|
+
// or the reading process failed.
|
265
|
+
return NO;
|
266
|
+
}
|
267
|
+
|
268
|
+
if (fileFD != NULL_FD)
|
269
|
+
{
|
270
|
+
// File has already been opened.
|
271
|
+
return YES;
|
272
|
+
}
|
273
|
+
|
274
|
+
return [self openFileAndSetupReadSource];
|
275
|
+
}
|
276
|
+
|
277
|
+
- (UInt64)contentLength
|
278
|
+
{
|
279
|
+
HTTPLogTrace2(@"%@[%p]: contentLength - %llu", THIS_FILE, self, fileLength);
|
280
|
+
|
281
|
+
return fileLength;
|
282
|
+
}
|
283
|
+
|
284
|
+
- (UInt64)offset
|
285
|
+
{
|
286
|
+
HTTPLogTrace();
|
287
|
+
|
288
|
+
return fileOffset;
|
289
|
+
}
|
290
|
+
|
291
|
+
- (void)setOffset:(UInt64)offset
|
292
|
+
{
|
293
|
+
HTTPLogTrace2(@"%@[%p]: setOffset:%llu", THIS_FILE, self, offset);
|
294
|
+
|
295
|
+
if (![self openFileIfNeeded])
|
296
|
+
{
|
297
|
+
// File opening failed,
|
298
|
+
// or response has been aborted due to another error.
|
299
|
+
return;
|
300
|
+
}
|
301
|
+
|
302
|
+
fileOffset = offset;
|
303
|
+
readOffset = offset;
|
304
|
+
|
305
|
+
off_t result = lseek(fileFD, (off_t)offset, SEEK_SET);
|
306
|
+
if (result == -1)
|
307
|
+
{
|
308
|
+
HTTPLogError(@"%@[%p]: lseek failed - errno(%i) filePath(%@)", THIS_FILE, self, errno, filePath);
|
309
|
+
|
310
|
+
[self abort];
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
314
|
+
- (NSData *)readDataOfLength:(NSUInteger)length
|
315
|
+
{
|
316
|
+
HTTPLogTrace2(@"%@[%p]: readDataOfLength:%lu", THIS_FILE, self, (unsigned long)length);
|
317
|
+
|
318
|
+
if (data)
|
319
|
+
{
|
320
|
+
NSUInteger dataLength = [data length];
|
321
|
+
|
322
|
+
HTTPLogVerbose(@"%@[%p]: Returning data of length %lu", THIS_FILE, self, (unsigned long)dataLength);
|
323
|
+
|
324
|
+
fileOffset += dataLength;
|
325
|
+
|
326
|
+
NSData *result = data;
|
327
|
+
data = nil;
|
328
|
+
|
329
|
+
return result;
|
330
|
+
}
|
331
|
+
else
|
332
|
+
{
|
333
|
+
if (![self openFileIfNeeded])
|
334
|
+
{
|
335
|
+
// File opening failed,
|
336
|
+
// or response has been aborted due to another error.
|
337
|
+
return nil;
|
338
|
+
}
|
339
|
+
|
340
|
+
dispatch_sync(readQueue, ^{
|
341
|
+
|
342
|
+
NSAssert(readSourceSuspended, @"Invalid logic - perhaps HTTPConnection has changed.");
|
343
|
+
|
344
|
+
readRequestLength = length;
|
345
|
+
[self resumeReadSource];
|
346
|
+
});
|
347
|
+
|
348
|
+
return nil;
|
349
|
+
}
|
350
|
+
}
|
351
|
+
|
352
|
+
- (BOOL)isDone
|
353
|
+
{
|
354
|
+
BOOL result = (fileOffset == fileLength);
|
355
|
+
|
356
|
+
HTTPLogTrace2(@"%@[%p]: isDone - %@", THIS_FILE, self, (result ? @"YES" : @"NO"));
|
357
|
+
|
358
|
+
return result;
|
359
|
+
}
|
360
|
+
|
361
|
+
- (NSString *)filePath
|
362
|
+
{
|
363
|
+
return filePath;
|
364
|
+
}
|
365
|
+
|
366
|
+
- (BOOL)isAsynchronous
|
367
|
+
{
|
368
|
+
HTTPLogTrace();
|
369
|
+
|
370
|
+
return YES;
|
371
|
+
}
|
372
|
+
|
373
|
+
- (void)connectionDidClose
|
374
|
+
{
|
375
|
+
HTTPLogTrace();
|
376
|
+
|
377
|
+
if (fileFD != NULL_FD)
|
378
|
+
{
|
379
|
+
dispatch_sync(readQueue, ^{
|
380
|
+
|
381
|
+
// Prevent any further calls to the connection
|
382
|
+
connection = nil;
|
383
|
+
|
384
|
+
// Cancel the readSource.
|
385
|
+
// We do this here because the readSource's eventBlock has retained self.
|
386
|
+
// In other words, if we don't cancel the readSource, we will never get deallocated.
|
387
|
+
|
388
|
+
[self cancelReadSource];
|
389
|
+
});
|
390
|
+
}
|
391
|
+
}
|
392
|
+
|
393
|
+
- (void)dealloc
|
394
|
+
{
|
395
|
+
HTTPLogTrace();
|
396
|
+
|
397
|
+
#if !OS_OBJECT_USE_OBJC
|
398
|
+
if (readQueue) dispatch_release(readQueue);
|
399
|
+
#endif
|
400
|
+
|
401
|
+
if (readBuffer)
|
402
|
+
free(readBuffer);
|
403
|
+
}
|
404
|
+
|
405
|
+
@end
|