Guest User

Untitled

a guest
Oct 15th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. //
  2. // LBCHTTPPostBody.h
  3. // LBCCore
  4. //
  5. // Created by Jeremy Foo on 22/5/12.
  6. // Copyright (c) 2012 BOB FTW PTE LTD. All rights reserved.
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  9. // this software and associated documentation files (the "Software"), to deal in
  10. // the Software without restriction, including without limitation the rights to
  11. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  12. // the Software, and to permit persons to whom the Software is furnished to do so,
  13. // subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be included in all
  16. // copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. // SOFTWARE.
  25.  
  26. #import <Foundation/Foundation.h>
  27.  
  28. // result is either a stream file NSURL or a NSData
  29. typedef void (^LBCHTTPPostBodyGenerationCompletionHandler)(BOOL isStreamFile, NSString *contentType, NSString *contentLength, id result, NSError *error);
  30.  
  31. typedef enum {
  32. LBCHTTPPostBodyNoSuchStreamFileError,
  33. LBCHTTPPostBodyWrongURLPathSpecifiedError
  34. } LBCHTTPPostBodyErrorStatus;
  35.  
  36. extern NSString *const LBCHTTPPostBodyErrorDomain;
  37.  
  38. @interface LBCHTTPPostBody : NSObject <NSStreamDelegate, NSCoding>
  39.  
  40. @property (readonly) NSMutableDictionary *parameters;
  41.  
  42. +(void)performStreamGenerationOfParamters:(NSDictionary *)params toPath:(NSURL *)path completion:(LBCHTTPPostBodyGenerationCompletionHandler)completion;
  43. +(void)performAutomaticHTTPBodyGenerationOfParameters:(NSDictionary *)params completion:(LBCHTTPPostBodyGenerationCompletionHandler)completion;
  44. -(id)initWithHTTPParameters:(NSDictionary *)params;
  45.  
  46. -(void)performAutomatic:(BOOL)automatic HTTPBodyGenerationWithCompletion:(LBCHTTPPostBodyGenerationCompletionHandler)completion;
  47. -(void)performStreamGenerationToPath:(NSURL *)path completion:(LBCHTTPPostBodyGenerationCompletionHandler)completion;
  48.  
  49. // HTTPBody Specific Methods
  50. +(BOOL)isExistingFileURLForObject:(id)obj;
  51. +(BOOL)needMultiPartForParameters:(NSDictionary *)params hasExternalFile:(BOOL *)externalFile;
  52.  
  53. // NSData Convinence Methods
  54. +(NSData *)octetStreamHeaderForName:(NSString *)name filename:(NSString *)filename;
  55. +(NSData *)octetStreamFooter;
  56. +(void)appendData:(NSMutableData *)data key:(NSString *)key value:(NSString *)value;
  57. +(void)appendData:(NSMutableData *)data key:(NSString *)key data:(NSData *)dataValue;
  58. +(NSInteger)appendOutputStream:(NSOutputStream *)stream key:(NSString *)key value:(NSString *)value;
  59. +(NSInteger)appendOutputStream:(NSOutputStream *)stream key:(NSString *)key data:(NSData *)dataValue;
  60.  
  61. // String Utilities
  62. +(NSString *)hashForData:(NSData *)data;
  63. +(NSString *)urlEncodedStringFromParams:(NSDictionary *)params;
  64. +(NSString *)escapeString:(NSString *)str;
  65. +(NSString *)escapeString:(NSString *)str withEscapees:(NSString *)escapees;
  66.  
  67. +(NSString *)multipartBoundary;
  68. +(NSString *)contentTypeForMultipart;
  69. +(NSURL *)fileURLForTemporaryStreamFile;
  70. @end
Add Comment
Please, Sign In to add comment