Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Commit

Permalink
conventions and leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
zbowling committed Nov 9, 2011
1 parent 2a939e5 commit 9a6d541
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
3 changes: 2 additions & 1 deletion AFNetworking/AFHTTPClient.h
Expand Up @@ -372,10 +372,11 @@ typedef enum {
@param fileURL The URL corresponding to the file whose content will be appended to the form.
@param name The name to be associated with the specified data. This parameter must not be `nil`.
@param error If an error occurs, upon return contains an `NSError` object that describes the problem.
@return if the operation was successful or there is an error in NSError return value
@discussion The filename and MIME type for this data in the form will be automatically generated, using `NSURLResponse` `-MIMEType` and `-suggestedFilename`.
*/
- (void)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error;
- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error;

/**
Appends encoded data to the form data.
Expand Down
13 changes: 9 additions & 4 deletions AFNetworking/AFHTTPClient.m
Expand Up @@ -334,7 +334,7 @@ - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlR
operation.successBlock = success;
operation.failureBlock = failure;

return operation;
return [operation autorelease];
}

- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation {
Expand Down Expand Up @@ -463,13 +463,15 @@ - (void)appendPartWithFileData:(NSData *)data name:(NSString *)name fileName:(NS
[self appendPartWithHeaders:mutableHeaders body:data];
}

- (void)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error {
- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error {
if (![fileURL isFileURL]) {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
[userInfo setValue:fileURL forKey:NSURLErrorFailingURLErrorKey];
[userInfo setValue:NSLocalizedString(@"Expected URL to be a file URL", nil) forKey:NSLocalizedFailureReasonErrorKey];
*error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo] autorelease];
return;
if (error){
*error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo] autorelease];
}
return NO;
}

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:fileURL];
Expand All @@ -480,7 +482,10 @@ - (void)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSEr

if (response && !error) {
[self appendPartWithFileData:data name:name fileName:[response suggestedFilename] mimeType:[response MIMEType]];
return YES;
}
return NO;

}

- (void)appendData:(NSData *)data {
Expand Down
27 changes: 16 additions & 11 deletions AFNetworking/AFHTTPRequestOperation.m
Expand Up @@ -74,27 +74,32 @@ - (id)initWithRequest:(NSURLRequest *)request {
//by default we will use the queue that created the request.
self.callbackQueue = dispatch_get_current_queue();

__block AFHTTPRequestOperation *blockSelf = [self retain];
super.completionBlock = ^ {
if (_completionBlock)
_completionBlock(); //call any child completion blocks that may have been passed in that they may want to run
if (blockSelf->_completionBlock) {
blockSelf->_completionBlock(); //call any child completion blocks that may have been passed in that they may want to run
}

if ([self isCancelled]) {
if ([blockSelf isCancelled]) {
[blockSelf release];
return;
}

if (self.HTTPError) {
if (self.responseProcessedBlock) {
dispatch_async(self.callbackQueue, ^(void) {
self.responseProcessedBlock();
if (blockSelf.HTTPError) {
if (blockSelf.responseProcessedBlock) {
dispatch_async(blockSelf.callbackQueue, ^(void) {
blockSelf.responseProcessedBlock();
[blockSelf release];
});
}
} else {
dispatch_async(request_operation_processing_queue(), ^(void) {
[self processResponse];
dispatch_async(self.callbackQueue, ^(void) {
if (self.responseProcessedBlock) {
self.responseProcessedBlock();
[blockSelf processResponse];
dispatch_async(blockSelf.callbackQueue, ^(void) {
if (blockSelf.responseProcessedBlock) {
blockSelf.responseProcessedBlock();
}
[blockSelf release];
});
});
}
Expand Down

0 comments on commit 9a6d541

Please sign in to comment.