You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/07/11 23:24:31 UTC
[2/3] ios commit: Change mutable parameters to non-mutable ones in
CDVFileTransfer.
Change mutable parameters to non-mutable ones in CDVFileTransfer.
-Moved NSMutableArray+Comparisons out of NSMutableArray+QueueAdditions
and it its own file, and applie it to NSArray instead of NSMutableArray
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/e6429255
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/e6429255
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/e6429255
Branch: refs/heads/master
Commit: e64292557dc4988fe80dabdaae96b6af4843de53
Parents: 07f2c00
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Jul 9 23:25:35 2012 -0400
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Wed Jul 11 14:23:01 2012 -0700
----------------------------------------------------------------------
CordovaLib/Classes/CDV.h | 1 +
CordovaLib/Classes/CDVFileTransfer.h | 6 +-
CordovaLib/Classes/CDVFileTransfer.m | 28 +++++-----
CordovaLib/Classes/CDVSound.m | 1 +
CordovaLib/Classes/NSArray+Comparisons.h | 27 ++++++++++
CordovaLib/Classes/NSArray+Comparisons.m | 40 +++++++++++++++
CordovaLib/Classes/NSMutableArray+QueueAdditions.h | 7 ---
CordovaLib/Classes/NSMutableArray+QueueAdditions.m | 20 -------
CordovaLib/CordovaLib.xcodeproj/project.pbxproj | 16 ++++++
9 files changed, 102 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/e6429255/CordovaLib/Classes/CDV.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDV.h b/CordovaLib/Classes/CDV.h
index b402604..c056b4e 100644
--- a/CordovaLib/Classes/CDV.h
+++ b/CordovaLib/Classes/CDV.h
@@ -47,6 +47,7 @@
#import "CDVWhitelist.h"
#import "CDVLocalStorage.h"
+#import "NSArray+Comparisons.h"
#import "NSData+Base64.h"
#import "NSDictionary+Extensions.h"
#import "NSMutableArray+QueueAdditions.h"
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/e6429255/CordovaLib/Classes/CDVFileTransfer.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.h b/CordovaLib/Classes/CDVFileTransfer.h
index 1419434..4289074 100644
--- a/CordovaLib/Classes/CDVFileTransfer.h
+++ b/CordovaLib/Classes/CDVFileTransfer.h
@@ -38,12 +38,12 @@ typedef int CDVFileTransferDirection;
}
-- (void) upload:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
-- (void) download:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) upload:(NSArray*)arguments withDict:(NSDictionary*)options;
+- (void) download:(NSArray*)arguments withDict:(NSDictionary*)options;
- (NSString*) escapePathComponentForUrlString:(NSString*)urlString;
// Visible for testing.
-- (NSURLRequest*) requestForUpload:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (NSURLRequest*) requestForUpload:(NSArray*)arguments withDict:(NSDictionary*)options;
-(NSMutableDictionary*) createFileTransferError:(int)code AndSource:(NSString*)source AndTarget:(NSString*)target;
-(NSMutableDictionary*) createFileTransferError:(int)code
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/e6429255/CordovaLib/Classes/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.m b/CordovaLib/Classes/CDVFileTransfer.m
index 4beaf42..fb3a723 100644
--- a/CordovaLib/Classes/CDVFileTransfer.m
+++ b/CordovaLib/Classes/CDVFileTransfer.m
@@ -22,11 +22,13 @@
#include <CFNetwork/CFNetwork.h>
@interface CDVFileTransfer ()
-- (CDVFileTransferDelegate*) delegateForUpload:(NSMutableArray*)arguments;
+- (CDVFileTransferDelegate*) delegateForUpload:(NSArray*)arguments;
@end
// Buffer size to use for streaming uploads.
static const NSUInteger kStreamBufferSize = 32768;
+// Magic value within the options dict used to set a cookie.
+static NSString* kOptionsKeyCookie = @"__cookie";
// Writes the given data to the stream in a blocking way.
// If successful, returns bytesToWrite.
@@ -77,7 +79,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) {
return [urlString stringByAppendingString:pathComponent];
}
-- (NSURLRequest*) requestForUpload:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
+- (NSURLRequest*) requestForUpload:(NSArray*)arguments withDict:(NSDictionary*)options {
NSString* callbackId = [arguments objectAtIndex:0];
// arguments order from js: [filePath, server, fileKey, fileName, mimeType, params, debug, chunkedMode]
@@ -98,7 +100,6 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) {
// http://developer.apple.com/library/ios/#samplecode/SimpleURLConnections/Listings/PostController_m.html
chunkedMode = NO;
}
- NSMutableDictionary* params = options;
// Extract the path part out of a file: URL.
NSString* filePath = [target hasPrefix:@"/"] ? [[target copy] autorelease] : [[NSURL URLWithString:target] path];
@@ -127,16 +128,15 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary: [self createFileTransferError:errorCode AndSource:target AndTarget:server]];
[self writeJavascript:[result toErrorCallbackString:callbackId]];
- return;
+ return nil;
}
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req setHTTPMethod:@"POST"];
// Magic value to set a cookie
- if([params objectForKey:@"__cookie"]) {
- [req setValue:[params objectForKey:@"__cookie"] forHTTPHeaderField:@"Cookie"];
- [params removeObjectForKey:@"__cookie"];
+ if([options objectForKey:kOptionsKeyCookie]) {
+ [req setValue:[options objectForKey:kOptionsKeyCookie] forHTTPHeaderField:@"Cookie"];
[req setHTTPShouldHandleCookies:NO];
}
@@ -152,7 +152,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) {
[req setValue: userAgent forHTTPHeaderField:@"User-Agent"];
}
- NSMutableDictionary* headers = [params objectForKey:@"headers"];
+ NSDictionary* headers = [options objectForKey:@"headers"];
NSEnumerator *enumerator = [headers keyEnumerator];
id val;
NSString *nkey;
@@ -175,12 +175,12 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) {
}
NSMutableData *postBodyBeforeFile = [NSMutableData data];
- enumerator = [params keyEnumerator];
+ enumerator = [options keyEnumerator];
id key;
while ((key = [enumerator nextObject])) {
- val = [params objectForKey:key];
- if(!val || val == [NSNull null]) {
+ val = [options objectForKey:key];
+ if(!val || val == [NSNull null] || [key isEqualToString:kOptionsKeyCookie]) {
continue;
}
// if it responds to stringValue selector (eg NSNumber) get the NSString
@@ -244,7 +244,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) {
return req;
}
-- (CDVFileTransferDelegate*) delegateForUpload:(NSMutableArray*)arguments {
+- (CDVFileTransferDelegate*) delegateForUpload:(NSArray*)arguments {
NSString* callbackId = [arguments objectAtIndex:0];
NSString* target = (NSString*)[arguments objectAtIndex:1];
NSString* server = (NSString*)[arguments objectAtIndex:2];
@@ -258,13 +258,13 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream) {
return delegate;
}
-- (void) upload:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
+- (void) upload:(NSArray*)arguments withDict:(NSDictionary*)options {
NSURLRequest* req = [self requestForUpload:arguments withDict:options];
CDVFileTransferDelegate* delegate = [self delegateForUpload:arguments];
[NSURLConnection connectionWithRequest:req delegate:delegate];
}
-- (void) download:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
+- (void) download:(NSArray*)arguments withDict:(NSDictionary*)options {
DLog(@"File Transfer downloading file...");
NSString * callbackId = [arguments objectAtIndex:0];
NSString * sourceUrl = [arguments objectAtIndex:1];
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/e6429255/CordovaLib/Classes/CDVSound.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVSound.m b/CordovaLib/Classes/CDVSound.m
index b0a1e2b..86be107 100644
--- a/CordovaLib/Classes/CDVSound.m
+++ b/CordovaLib/Classes/CDVSound.m
@@ -20,6 +20,7 @@
#import "CDVSound.h"
#import "CDVViewController.h"
+#import "NSArray+Comparisons.h"
#define DOCUMENTS_SCHEME_PREFIX @"documents://"
#define HTTP_SCHEME_PREFIX @"http://"
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/e6429255/CordovaLib/Classes/NSArray+Comparisons.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/NSArray+Comparisons.h b/CordovaLib/Classes/NSArray+Comparisons.h
new file mode 100755
index 0000000..4633f1a
--- /dev/null
+++ b/CordovaLib/Classes/NSArray+Comparisons.h
@@ -0,0 +1,27 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+
+@interface NSArray (Comparisons)
+
+- (id) objectAtIndex:(NSUInteger)index withDefault:(id)aDefault;
+
+@end
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/e6429255/CordovaLib/Classes/NSArray+Comparisons.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/NSArray+Comparisons.m b/CordovaLib/Classes/NSArray+Comparisons.m
new file mode 100755
index 0000000..5df34fa
--- /dev/null
+++ b/CordovaLib/Classes/NSArray+Comparisons.m
@@ -0,0 +1,40 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "NSArray+Comparisons.h"
+
+@implementation NSArray (Comparisons)
+
+- (id) objectAtIndex:(NSUInteger)index withDefault:(id)aDefault
+{
+ id obj = nil;
+ @try {
+ obj = [self objectAtIndex:index];
+ if (obj == [NSNull null] || obj == nil) {
+ return aDefault;
+ }
+ }
+ @catch (NSException* exception) {
+ NSLog(@"Exception - Name: %@ Reason: %@", [exception name], [exception reason]);
+ }
+
+ return obj;
+}
+
+@end
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/e6429255/CordovaLib/Classes/NSMutableArray+QueueAdditions.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/NSMutableArray+QueueAdditions.h b/CordovaLib/Classes/NSMutableArray+QueueAdditions.h
index dd8ba1b..e86632e 100755
--- a/CordovaLib/Classes/NSMutableArray+QueueAdditions.h
+++ b/CordovaLib/Classes/NSMutableArray+QueueAdditions.h
@@ -28,10 +28,3 @@
- (void) enqueue:(id)obj;
@end
-
-
-@interface NSMutableArray (Comparisons)
-
-- (id) objectAtIndex:(NSUInteger)index withDefault:(id)aDefault;
-
-@end
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/e6429255/CordovaLib/Classes/NSMutableArray+QueueAdditions.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/NSMutableArray+QueueAdditions.m b/CordovaLib/Classes/NSMutableArray+QueueAdditions.m
index 4267947..69acdaf 100755
--- a/CordovaLib/Classes/NSMutableArray+QueueAdditions.m
+++ b/CordovaLib/Classes/NSMutableArray+QueueAdditions.m
@@ -56,23 +56,3 @@
}
@end
-
-@implementation NSMutableArray (Comparisons)
-
-- (id) objectAtIndex:(NSUInteger)index withDefault:(id)aDefault
-{
- id obj = nil;
- @try {
- obj = [self objectAtIndex:index];
- if (obj == [NSNull null] || obj == nil) {
- return aDefault;
- }
- }
- @catch (NSException* exception) {
- NSLog(@"Exception - Name: %@ Reason: %@", [exception name], [exception reason]);
- }
-
- return obj;
-}
-
-@end
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/e6429255/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
index bd63d59..12ab509 100644
--- a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
+++ b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
@@ -188,6 +188,11 @@
C937A4571337599E002C4C79 /* CDVFileTransfer.m in Sources */ = {isa = PBXBuildFile; fileRef = C937A4551337599E002C4C79 /* CDVFileTransfer.m */; };
EBA3550D15A5E8D100F4DE24 /* VERSION in Resources */ = {isa = PBXBuildFile; fileRef = 30325A0B136B343700982B63 /* VERSION */; };
EBA3554615A731F100F4DE24 /* CDVFakeFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3554515A731F100F4DE24 /* CDVFakeFileManager.m */; };
+ EBA3556F15ABD0C900F4DE24 /* CDVFileTransferTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3556E15ABD0C900F4DE24 /* CDVFileTransferTests.m */; };
+ EBA3557315ABD38C00F4DE24 /* NSArray+Comparisons.h in Headers */ = {isa = PBXBuildFile; fileRef = EBA3557115ABD38C00F4DE24 /* NSArray+Comparisons.h */; };
+ EBA3557415ABD38C00F4DE24 /* NSArray+Comparisons.h in Headers */ = {isa = PBXBuildFile; fileRef = EBA3557115ABD38C00F4DE24 /* NSArray+Comparisons.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ EBA3557515ABD38C00F4DE24 /* NSArray+Comparisons.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3557215ABD38C00F4DE24 /* NSArray+Comparisons.m */; };
+ EBA3557615ABD38C00F4DE24 /* NSArray+Comparisons.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3557215ABD38C00F4DE24 /* NSArray+Comparisons.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -311,6 +316,9 @@
EBA3550F15A5F18900F4DE24 /* CDVWebViewTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CDVWebViewTest.h; sourceTree = "<group>"; };
EBA3554415A731F100F4DE24 /* CDVFakeFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVFakeFileManager.h; sourceTree = "<group>"; };
EBA3554515A731F100F4DE24 /* CDVFakeFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVFakeFileManager.m; sourceTree = "<group>"; };
+ EBA3556E15ABD0C900F4DE24 /* CDVFileTransferTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVFileTransferTests.m; sourceTree = "<group>"; };
+ EBA3557115ABD38C00F4DE24 /* NSArray+Comparisons.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSArray+Comparisons.h"; path = "Classes/NSArray+Comparisons.h"; sourceTree = "<group>"; };
+ EBA3557215ABD38C00F4DE24 /* NSArray+Comparisons.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSArray+Comparisons.m"; path = "Classes/NSArray+Comparisons.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -463,6 +471,7 @@
EBA3550F15A5F18900F4DE24 /* CDVWebViewTest.h */,
30B342F415224B360070E6A5 /* CDVWebViewTest.m */,
30D1B08B15A2B36D0060C291 /* CDVBase64Tests.m */,
+ EBA3556E15ABD0C900F4DE24 /* CDVFileTransferTests.m */,
3062D1AD151D4D9D000D9128 /* CDVLocalStorageTests.m */,
686357B9141002F200DF4CF2 /* CDVPluginResultJSONSerializationTests.m */,
30356213141049E1006C2D43 /* CDVWhitelistTests.m */,
@@ -543,6 +552,8 @@
children = (
3062D11E151D0EDB000D9128 /* UIDevice+Extensions.h */,
3062D11F151D0EDB000D9128 /* UIDevice+Extensions.m */,
+ EBA3557115ABD38C00F4DE24 /* NSArray+Comparisons.h */,
+ EBA3557215ABD38C00F4DE24 /* NSArray+Comparisons.m */,
8887FD281090FBE7009987E8 /* NSDictionary+Extensions.h */,
8887FD291090FBE7009987E8 /* NSDictionary+Extensions.m */,
302965BB13A94E9D007046C5 /* CDVDebug.h */,
@@ -616,6 +627,7 @@
3062D121151D0EDB000D9128 /* UIDevice+Extensions.h in Headers */,
3034979D1513D56A0090E688 /* CDVLocalStorage.h in Headers */,
3E768770156A90EE00EB6FA3 /* CDVLogger.h in Headers */,
+ EBA3557415ABD38C00F4DE24 /* NSArray+Comparisons.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -657,6 +669,7 @@
3034979C1513D56A0090E688 /* CDVLocalStorage.h in Headers */,
3062D120151D0EDB000D9128 /* UIDevice+Extensions.h in Headers */,
3E76876F156A90EE00EB6FA3 /* CDVLogger.h in Headers */,
+ EBA3557315ABD38C00F4DE24 /* NSArray+Comparisons.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -910,6 +923,7 @@
3034979F1513D56A0090E688 /* CDVLocalStorage.m in Sources */,
3062D123151D0EDB000D9128 /* UIDevice+Extensions.m in Sources */,
3E76876E156A90EE00EB6FA3 /* CDVLogger.m in Sources */,
+ EBA3557615ABD38C00F4DE24 /* NSArray+Comparisons.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -934,6 +948,7 @@
30B342F515224B360070E6A5 /* CDVWebViewTest.m in Sources */,
30D1B08C15A2B36D0060C291 /* CDVBase64Tests.m in Sources */,
EBA3554615A731F100F4DE24 /* CDVFakeFileManager.m in Sources */,
+ EBA3556F15ABD0C900F4DE24 /* CDVFileTransferTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -971,6 +986,7 @@
3034979E1513D56A0090E688 /* CDVLocalStorage.m in Sources */,
3062D122151D0EDB000D9128 /* UIDevice+Extensions.m in Sources */,
3E76876D156A90EE00EB6FA3 /* CDVLogger.m in Sources */,
+ EBA3557515ABD38C00F4DE24 /* NSArray+Comparisons.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};