├── DropboxSDK ├── DBAccountInfo.h ├── DBAccountInfo.m ├── DBCreateAccountController.h ├── DBCreateAccountController.m ├── DBError.h ├── DBError.m ├── DBLoadingView.h ├── DBLoadingView.m ├── DBLoginController.h ├── DBLoginController.m ├── DBMetadata.h ├── DBMetadata.m ├── DBQuota.h ├── DBQuota.m ├── DBRequest.h ├── DBRequest.m ├── DBRestClient.h ├── DBRestClient.m ├── DBSession.h ├── DBSession.m ├── DropboxSDK.h ├── JSON │ ├── JSON.h │ ├── NSObject+SBJSON.h │ ├── NSObject+SBJSON.m │ ├── NSString+SBJSON.h │ ├── NSString+SBJSON.m │ ├── SBJSON.h │ ├── SBJSON.m │ ├── SBJsonBase.h │ ├── SBJsonBase.m │ ├── SBJsonParser.h │ ├── SBJsonParser.m │ ├── SBJsonWriter.h │ └── SBJsonWriter.m ├── LICENSE ├── MPOAuth │ ├── Crypto │ │ ├── Base64Transcoder.c │ │ └── Base64Transcoder.h │ ├── MPDebug.h │ ├── MPOAuth.h │ ├── MPOAuthAPI.h │ ├── MPOAuthAPI.m │ ├── MPOAuthAPIRequestLoader.h │ ├── MPOAuthAPIRequestLoader.m │ ├── MPOAuthAuthenticationMethod.h │ ├── MPOAuthAuthenticationMethod.m │ ├── MPOAuthAuthenticationMethodOAuth.h │ ├── MPOAuthAuthenticationMethodOAuth.m │ ├── MPOAuthConnection.h │ ├── MPOAuthConnection.m │ ├── MPOAuthCredentiaIConcreteStore+KeychainAdditionsMac.m │ ├── MPOAuthCredentialConcreteStore+KeychainAdditions.h │ ├── MPOAuthCredentialConcreteStore+KeychainAdditionsiPhone.m │ ├── MPOAuthCredentialConcreteStore.h │ ├── MPOAuthCredentialConcreteStore.m │ ├── MPOAuthCredentialStore.h │ ├── MPOAuthParameterFactory.h │ ├── MPOAuthSignatureParameter.h │ ├── MPOAuthSignatureParameter.m │ ├── MPOAuthURLRequest.h │ ├── MPOAuthURLRequest.m │ ├── MPOAuthURLResponse.h │ ├── MPOAuthURLResponse.m │ ├── MPURLRequestParameter.h │ ├── MPURLRequestParameter.m │ ├── NSString+URLEscapingAdditions.h │ ├── NSString+URLEscapingAdditions.m │ ├── NSURL+MPURLParameterAdditions.h │ ├── NSURL+MPURLParameterAdditions.m │ ├── NSURLResponse+Encoding.h │ └── NSURLResponse+Encoding.m ├── NSString+Dropbox.h ├── NSString+Dropbox.m └── Resources │ ├── db_background.png │ ├── db_create_account.png │ ├── db_create_account@2x.png │ ├── db_create_account_button.png │ ├── db_create_account_button_down.png │ ├── db_link_button.png │ ├── db_link_button_down.png │ ├── db_link_header.png │ ├── db_link_header@2x.png │ ├── db_logo.png │ └── db_logo@2x.png ├── DropboxSync.xcodeproj ├── 0hoo.mode1v3 ├── 0hoo.pbxuser ├── jesse.pbxuser ├── jesse.perspectivev3 ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── jesse.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── jesse.xcuserdatad │ ├── xcdebugger │ └── Breakpoints.xcbkptlist │ └── xcschemes │ ├── DropboxSync.xcscheme │ ├── Tests.xcscheme │ └── xcschememanagement.plist ├── LICENSE ├── README.markdown ├── Source ├── DeleteLocalPathOperation.h ├── DeleteLocalPathOperation.m ├── DeletePathOperation.h ├── DeletePathOperation.m ├── DropboxSync_Prefix.pch ├── FolderSyncPathOperation.h ├── FolderSyncPathOperation.m ├── GetPathOperation.h ├── GetPathOperation.m ├── NSFileManager_Additions.h ├── NSFileManager_Additions.m ├── NSSet_Additions.h ├── NSSet_Additions.m ├── PathController.h ├── PathController.m ├── PathControllerDelegate.h ├── PathController_Private.h ├── PathMetadata.h ├── PathMetadata.m ├── PathMetadata.xcdatamodeld │ ├── .xccurrentversion │ └── PathMetadata.xcdatamodel │ │ ├── elements │ │ └── layout ├── PathOperation.h ├── PathOperation.m ├── PutPathOperation.h └── PutPathOperation.m └── Tests ├── DropboxTestFolderFixture ├── 1 はじめ.txt ├── 2 ū.txt ├── 3.txt └── 4 ぜら │ ├── boo │ └── hello.txt │ └── test.pages ├── GHUnitIOS.framework ├── GHUnitIOS ├── Headers ├── Resources └── Versions │ ├── A │ ├── GHUnitIOS │ ├── Headers │ │ ├── GHAsyncTestCase.h │ │ ├── GHTest+JUnitXML.h │ │ ├── GHTest.h │ │ ├── GHTestCase.h │ │ ├── GHTestGroup+JUnitXML.h │ │ ├── GHTestGroup.h │ │ ├── GHTestMacros.h │ │ ├── GHTestOperation.h │ │ ├── GHTestRunner.h │ │ ├── GHTestSuite.h │ │ ├── GHTesting.h │ │ ├── GHUnit.h │ │ ├── GHUnitIOS.h │ │ ├── GHUnitIPhoneAppDelegate.h │ │ ├── GHUnitIPhoneTableViewDataSource.h │ │ ├── GHUnitIPhoneTestViewController.h │ │ ├── GHUnitIPhoneView.h │ │ ├── GHUnitIPhoneViewController.h │ │ ├── NSException+GHTestFailureExceptions.h │ │ └── NSValue+GHValueFormatter.h │ └── Resources │ │ └── Info.plist │ └── Current ├── GHUnitIPhoneTestMain.m ├── PathControllerTests.h ├── PathControllerTests.m └── Tests-Info.plist /DropboxSDK/DBAccountInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // DBAccountInfo.h 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 5/3/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | 10 | #import "DBQuota.h" 11 | 12 | @interface DBAccountInfo : NSObject { 13 | NSString* country; 14 | NSString* displayName; 15 | DBQuota* quota; 16 | NSString* userId; 17 | NSString* referralLink; 18 | } 19 | 20 | - (id)initWithDictionary:(NSDictionary*)dict; 21 | 22 | @property (nonatomic, readonly) NSString* country; 23 | @property (nonatomic, readonly) NSString* displayName; 24 | @property (nonatomic, readonly) DBQuota* quota; 25 | @property (nonatomic, readonly) NSString* userId; 26 | @property (nonatomic, readonly) NSString* referralLink; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /DropboxSDK/DBAccountInfo.m: -------------------------------------------------------------------------------- 1 | // 2 | // DBAccountInfo.m 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 5/3/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | #import "DBAccountInfo.h" 10 | 11 | 12 | @implementation DBAccountInfo 13 | 14 | - (id)initWithDictionary:(NSDictionary*)dict { 15 | if ((self = [super init])) { 16 | country = [[dict objectForKey:@"country"] retain]; 17 | displayName = [[dict objectForKey:@"display_name"] retain]; 18 | quota = [[DBQuota alloc] initWithDictionary:[dict objectForKey:@"quota_info"]]; 19 | userId = [[[dict objectForKey:@"uid"] stringValue] retain]; 20 | referralLink = [[dict objectForKey:@"referral_link"] retain]; 21 | } 22 | return self; 23 | } 24 | 25 | - (void)dealloc { 26 | [country release]; 27 | [displayName release]; 28 | [quota release]; 29 | [userId release]; 30 | [referralLink release]; 31 | [super dealloc]; 32 | } 33 | 34 | @synthesize country; 35 | @synthesize displayName; 36 | @synthesize quota; 37 | @synthesize userId; 38 | @synthesize referralLink; 39 | 40 | 41 | #pragma mark NSCoding methods 42 | 43 | - (void)encodeWithCoder:(NSCoder*)coder { 44 | [coder encodeObject:country forKey:@"country"]; 45 | [coder encodeObject:displayName forKey:@"displayName"]; 46 | [coder encodeObject:quota forKey:@"quota"]; 47 | [coder encodeObject:userId forKey:@"userId"]; 48 | [coder encodeObject:referralLink forKey:@"referralLink"]; 49 | } 50 | 51 | - (id)initWithCoder:(NSCoder*)coder { 52 | self = [super init]; 53 | country = [[coder decodeObjectForKey:@"country"] retain]; 54 | displayName = [[coder decodeObjectForKey:@"displayName"] retain]; 55 | quota = [[coder decodeObjectForKey:@"quota"] retain]; 56 | userId = [[coder decodeObjectForKey:@"userId"] retain]; 57 | referralLink = [[coder decodeObjectForKey:@"referralLink"] retain]; 58 | return self; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /DropboxSDK/DBCreateAccountController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DBCreateAccountController.h 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 5/20/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | 10 | @class DBLoadingView; 11 | @class DBLoginController; 12 | @class DBRestClient; 13 | 14 | @interface DBCreateAccountController : UIViewController { 15 | BOOL hasCreatedAccount; 16 | DBLoginController* loginController; 17 | DBRestClient* restClient; 18 | 19 | UITableView* tableView; 20 | UIView* headerView; 21 | UITableViewCell* firstNameCell; 22 | UITextField* firstNameField; 23 | UITableViewCell* lastNameCell; 24 | UITextField* lastNameField; 25 | UITableViewCell* emailCell; 26 | UITextField* emailField; 27 | UITableViewCell* passwordCell; 28 | UITextField* passwordField; 29 | UIView* footerView; 30 | UIActivityIndicatorView* activityIndicator; 31 | DBLoadingView* loadingView; 32 | } 33 | 34 | @property (nonatomic, assign) DBLoginController* loginController; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /DropboxSDK/DBError.h: -------------------------------------------------------------------------------- 1 | // 2 | // DBError.h 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 7/21/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | /* This file contains error codes and the dropbox error domain */ 10 | 11 | extern NSString* DBErrorDomain; 12 | 13 | // Error codes in the dropbox.com domain represent the HTTP status code if less than 1000 14 | typedef enum { 15 | DBErrorNone = 0, 16 | DBErrorGenericError = 1000, 17 | DBErrorFileNotFound, 18 | DBErrorInsufficientDiskSpace, 19 | } DBErrorCode; 20 | -------------------------------------------------------------------------------- /DropboxSDK/DBError.m: -------------------------------------------------------------------------------- 1 | // 2 | // DBError.m 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 7/21/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | #import "DBError.h" 10 | 11 | NSString* DBErrorDomain = @"dropbox.com"; 12 | -------------------------------------------------------------------------------- /DropboxSDK/DBLoadingView.h: -------------------------------------------------------------------------------- 1 | // 2 | // DBLoadingView.h 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 6/30/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface DBLoadingView : UIView { 13 | UIInterfaceOrientation orientation; 14 | UILabel* titleLabel; 15 | UIActivityIndicatorView* activityIndicator; 16 | UIImageView* imageView; 17 | } 18 | 19 | - (id)initWithTitle:(NSString*)title; 20 | 21 | - (void)setImage:(UIImage*)image; 22 | - (void)setOrientation:(UIInterfaceOrientation)orientation; 23 | 24 | - (void)show; 25 | - (void)dismissAnimated:(BOOL)animated; 26 | 27 | //@property (nonatomic, retain) NSString* title; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /DropboxSDK/DBLoginController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DBLoginController.h 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 5/20/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | 10 | @class DBLoadingView; 11 | @class DBRestClient; 12 | @protocol DBLoginControllerDelegate; 13 | 14 | @interface DBLoginController : UIViewController { 15 | BOOL hasAppeared; // Used to track whether the view totally onscreen 16 | id delegate; 17 | 18 | UITableView* tableView; 19 | UILabel* descriptionLabel; 20 | UITableViewCell* emailCell; 21 | UITextField* emailField; 22 | UITableViewCell* passwordCell; 23 | UITextField* passwordField; 24 | UIView* footerView; 25 | 26 | DBLoadingView* loadingView; 27 | UIActivityIndicatorView* activityIndicator; 28 | 29 | DBRestClient* restClient; 30 | } 31 | 32 | - (void)presentFromController:(UIViewController*)controller; 33 | 34 | @property (nonatomic, assign) id delegate; 35 | 36 | @end 37 | 38 | 39 | // This controller tells the delegate whether the user sucessfully logged in or not 40 | // The login controller will dismiss itself 41 | @protocol DBLoginControllerDelegate 42 | 43 | - (void)loginControllerDidLogin:(DBLoginController*)controller; 44 | - (void)loginControllerDidCancel:(DBLoginController*)controller; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /DropboxSDK/DBMetadata.h: -------------------------------------------------------------------------------- 1 | // 2 | // DBMetadata.h 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 5/3/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | 10 | @interface DBMetadata : NSObject { 11 | BOOL thumbnailExists; 12 | long long totalBytes; 13 | NSDate* lastModifiedDate; 14 | NSString* path; 15 | NSString *mimeType; 16 | BOOL isDirectory; 17 | NSArray* contents; 18 | NSString* hash; 19 | NSString* humanReadableSize; 20 | NSString* root; 21 | NSString* icon; 22 | long long revision; 23 | BOOL isDeleted; 24 | } 25 | 26 | - (id)initWithDictionary:(NSDictionary*)dict; 27 | 28 | @property (nonatomic, readonly) BOOL thumbnailExists; 29 | @property (nonatomic, readonly) long long totalBytes; 30 | @property (nonatomic, readonly) NSDate* lastModifiedDate; 31 | @property (nonatomic, readonly) NSString* path; 32 | @property (nonatomic, readonly) NSString* mimeType; 33 | @property (nonatomic, readonly) BOOL isDirectory; 34 | @property (nonatomic, readonly) NSArray* contents; 35 | @property (nonatomic, readonly) NSString* hash; 36 | @property (nonatomic, readonly) NSString* humanReadableSize; 37 | @property (nonatomic, readonly) NSString* root; 38 | @property (nonatomic, readonly) NSString* icon; 39 | @property (nonatomic, readonly) long long revision; 40 | @property (nonatomic, readonly) BOOL isDeleted; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /DropboxSDK/DBMetadata.m: -------------------------------------------------------------------------------- 1 | // 2 | // DBMetadata.m 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 5/3/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | #import "DBMetadata.h" 10 | 11 | 12 | @implementation DBMetadata 13 | 14 | + (NSDateFormatter*) dateFormatter { 15 | NSMutableDictionary* dictionary = [[NSThread currentThread] threadDictionary]; 16 | NSDateFormatter* dateFormatter = [dictionary objectForKey:@"DBMetadataDateFormatter"]; 17 | if (dateFormatter == nil) { 18 | dateFormatter = [[NSDateFormatter alloc] init]; 19 | dateFormatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]; 20 | dateFormatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss Z"; 21 | [dictionary setObject:dateFormatter forKey:@"DBMetadataDateFormatter"]; 22 | [dateFormatter release]; 23 | } 24 | return dateFormatter; 25 | } 26 | 27 | - (id)initWithDictionary:(NSDictionary*)dict { 28 | if ((self = [super init])) { 29 | thumbnailExists = [[dict objectForKey:@"thumb_exists"] boolValue]; 30 | totalBytes = [[dict objectForKey:@"bytes"] longLongValue]; 31 | 32 | if ([dict objectForKey:@"modified"]) { 33 | lastModifiedDate = [[[DBMetadata dateFormatter] dateFromString:[dict objectForKey:@"modified"]] retain]; 34 | } 35 | 36 | path = [[dict objectForKey:@"path"] retain]; 37 | mimeType = [[dict objectForKey:@"mime_type"] retain]; 38 | isDirectory = [[dict objectForKey:@"is_dir"] boolValue]; 39 | 40 | if ([dict objectForKey:@"contents"]) { 41 | NSArray* subfileDicts = [dict objectForKey:@"contents"]; 42 | NSMutableArray* mutableContents = 43 | [[NSMutableArray alloc] initWithCapacity:[subfileDicts count]]; 44 | for (NSDictionary* subfileDict in subfileDicts) { 45 | DBMetadata* subfile = [[DBMetadata alloc] initWithDictionary:subfileDict]; 46 | [mutableContents addObject:subfile]; 47 | [subfile release]; 48 | } 49 | contents = mutableContents; 50 | } 51 | 52 | hash = [[dict objectForKey:@"hash"] retain]; 53 | humanReadableSize = [[dict objectForKey:@"size"] retain]; 54 | root = [[dict objectForKey:@"root"] retain]; 55 | icon = [[dict objectForKey:@"icon"] retain]; 56 | revision = [[dict objectForKey:@"revision"] longLongValue]; 57 | isDeleted = [[dict objectForKey:@"is_deleted"] boolValue]; 58 | } 59 | return self; 60 | } 61 | 62 | - (void)dealloc { 63 | [lastModifiedDate release]; 64 | [path release]; 65 | [mimeType release]; 66 | [contents release]; 67 | [hash release]; 68 | [humanReadableSize release]; 69 | [root release]; 70 | [icon release]; 71 | [super dealloc]; 72 | } 73 | 74 | @synthesize thumbnailExists; 75 | @synthesize totalBytes; 76 | @synthesize lastModifiedDate; 77 | @synthesize path; 78 | @synthesize mimeType; 79 | @synthesize isDirectory; 80 | @synthesize contents; 81 | @synthesize hash; 82 | @synthesize humanReadableSize; 83 | @synthesize root; 84 | @synthesize icon; 85 | @synthesize revision; 86 | @synthesize isDeleted; 87 | 88 | 89 | #pragma mark NSCoding methods 90 | 91 | - (id)initWithCoder:(NSCoder*)coder { 92 | if ((self = [super init])) { 93 | thumbnailExists = [coder decodeBoolForKey:@"thumbnailExists"]; 94 | totalBytes = [coder decodeInt64ForKey:@"totalBytes"]; 95 | lastModifiedDate = [[coder decodeObjectForKey:@"lastModifiedDate"] retain]; 96 | path = [[coder decodeObjectForKey:@"path"] retain]; 97 | mimeType = [[coder decodeObjectForKey:@"mimeType"] retain]; 98 | isDirectory = [coder decodeBoolForKey:@"isDirectory"]; 99 | contents = [[coder decodeObjectForKey:@"contents"] retain]; 100 | hash = [[coder decodeObjectForKey:@"hash"] retain]; 101 | humanReadableSize = [[coder decodeObjectForKey:@"humanReadableSize"] retain]; 102 | root = [[coder decodeObjectForKey:@"root"] retain]; 103 | icon = [[coder decodeObjectForKey:@"icon"] retain]; 104 | revision = [coder decodeInt64ForKey:@"revision"]; 105 | isDeleted = [coder decodeBoolForKey:@"isDeleted"]; 106 | } 107 | return self; 108 | } 109 | 110 | - (void)encodeWithCoder:(NSCoder*)coder { 111 | [coder encodeBool:thumbnailExists forKey:@"thumbnailExists"]; 112 | [coder encodeInt64:totalBytes forKey:@"totalBytes"]; 113 | [coder encodeObject:lastModifiedDate forKey:@"lastModifiedDate"]; 114 | [coder encodeObject:path forKey:@"path"]; 115 | [coder encodeObject:mimeType forKey:@"mimeType"]; 116 | [coder encodeBool:isDirectory forKey:@"isDirectory"]; 117 | [coder encodeObject:contents forKey:@"contents"]; 118 | [coder encodeObject:hash forKey:@"hash"]; 119 | [coder encodeObject:humanReadableSize forKey:@"humanReadableSize"]; 120 | [coder encodeObject:root forKey:@"root"]; 121 | [coder encodeObject:icon forKey:@"icon"]; 122 | [coder encodeInt64:revision forKey:@"revision"]; 123 | [coder encodeBool:isDeleted forKey:@"isDeleted"]; 124 | } 125 | 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /DropboxSDK/DBQuota.h: -------------------------------------------------------------------------------- 1 | // 2 | // DBQuota.h 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 5/3/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | 10 | @interface DBQuota : NSObject { 11 | long long normalConsumedBytes; 12 | long long sharedConsumedBytes; 13 | long long totalBytes; 14 | } 15 | 16 | - (id)initWithDictionary:(NSDictionary*)dict; 17 | 18 | @property (nonatomic, readonly) long long normalConsumedBytes; 19 | @property (nonatomic, readonly) long long sharedConsumedBytes; 20 | @property (nonatomic, readonly) long long totalConsumedBytes; 21 | @property (nonatomic, readonly) long long totalBytes; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /DropboxSDK/DBQuota.m: -------------------------------------------------------------------------------- 1 | // 2 | // DBQuotaInfo.m 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 5/3/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | #import "DBQuota.h" 10 | 11 | 12 | @implementation DBQuota 13 | 14 | - (id)initWithDictionary:(NSDictionary*)dict { 15 | if ((self = [super init])) { 16 | normalConsumedBytes = [[dict objectForKey:@"normal"] longLongValue]; 17 | sharedConsumedBytes = [[dict objectForKey:@"shared"] longLongValue]; 18 | totalBytes = [[dict objectForKey:@"quota"] longLongValue]; 19 | } 20 | return self; 21 | } 22 | 23 | - (void)dealloc { 24 | [super dealloc]; 25 | } 26 | 27 | @synthesize normalConsumedBytes; 28 | @synthesize sharedConsumedBytes; 29 | @synthesize totalBytes; 30 | 31 | - (long long)totalConsumedBytes { 32 | return normalConsumedBytes + sharedConsumedBytes; 33 | } 34 | 35 | 36 | #pragma mark NSCoding methods 37 | 38 | - (void)encodeWithCoder:(NSCoder*)coder { 39 | [coder encodeInt64:normalConsumedBytes forKey:@"normalConsumedBytes"]; 40 | [coder encodeInt64:sharedConsumedBytes forKey:@"sharedConsumedBytes"]; 41 | [coder encodeInt64:totalBytes forKey:@"totalBytes"]; 42 | } 43 | 44 | - (id)initWithCoder:(NSCoder*)coder { 45 | self = [super init]; 46 | normalConsumedBytes = [coder decodeInt64ForKey:@"normalConsumedBytes"]; 47 | sharedConsumedBytes = [coder decodeInt64ForKey:@"sharedConsumedBytes"]; 48 | totalBytes = [coder decodeInt64ForKey:@"totalBytes"]; 49 | return self; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /DropboxSDK/DBRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // DBRestRequest.h 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 4/9/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | 10 | @protocol DBNetworkRequestDelegate; 11 | 12 | /* DBRestRequest will download a URL either into a file that you provied the name to or it will 13 | create an NSData object with the result. When it has completed downloading the URL, it will 14 | notify the target with a selector that takes the DBRestRequest as the only parameter. */ 15 | @interface DBRequest : NSObject { 16 | NSURLRequest* request; 17 | id target; 18 | SEL selector; 19 | NSURLConnection* urlConnection; 20 | NSFileHandle* fileHandle; 21 | 22 | SEL failureSelector; 23 | SEL downloadProgressSelector; 24 | SEL uploadProgressSelector; 25 | NSString* resultFilename; 26 | NSString* tempFilename; 27 | NSDictionary* userInfo; 28 | 29 | NSHTTPURLResponse* response; 30 | NSInteger bytesDownloaded; 31 | CGFloat downloadProgress; 32 | CGFloat uploadProgress; 33 | NSMutableData* resultData; 34 | NSError* error; 35 | } 36 | 37 | /* Set this to get called when _any_ request starts or stops. This should hook into whatever 38 | network activity indicator system you have. */ 39 | + (void)setNetworkRequestDelegate:(id)delegate; 40 | 41 | /* This constructor downloads the URL into the resultData object */ 42 | - (id)initWithURLRequest:(NSURLRequest*)request andInformTarget:(id)target selector:(SEL)selector; 43 | 44 | /* Cancels the request and prevents it from sending additional messages to the delegate. */ 45 | - (void)cancel; 46 | 47 | @property (nonatomic, assign) SEL failureSelector; // To send failure events to a different selector set this 48 | @property (nonatomic, assign) SEL downloadProgressSelector; // To receive download progress events set this 49 | @property (nonatomic, assign) SEL uploadProgressSelector; // To receive upload progress events set this 50 | @property (nonatomic, retain) NSString* resultFilename; // The file to put the HTTP body in, otherwise body is stored in resultData 51 | @property (nonatomic, retain) NSDictionary* userInfo; 52 | 53 | @property (nonatomic, readonly) NSURLRequest* request; 54 | @property (nonatomic, readonly) NSHTTPURLResponse* response; 55 | @property (nonatomic, readonly) NSInteger statusCode; 56 | @property (nonatomic, readonly) CGFloat downloadProgress; 57 | @property (nonatomic, readonly) CGFloat uploadProgress; 58 | @property (nonatomic, readonly) NSData* resultData; 59 | @property (nonatomic, readonly) NSString* resultString; 60 | @property (nonatomic, readonly) NSObject* resultJSON; 61 | @property (nonatomic, readonly) NSError* error; 62 | 63 | @end 64 | 65 | 66 | @protocol DBNetworkRequestDelegate 67 | 68 | - (void)networkRequestStarted; 69 | - (void)networkRequestStopped; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /DropboxSDK/DBSession.h: -------------------------------------------------------------------------------- 1 | // 2 | // DBSession.h 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 4/8/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | #import "MPOAuthCredentialConcreteStore.h" 10 | 11 | extern NSString* kDBDropboxAPIHost; 12 | extern NSString* kDBDropboxAPIContentHost; 13 | extern NSString* kDBDropboxAPIVersion; 14 | 15 | @protocol DBSessionDelegate; 16 | 17 | 18 | /* Creating and setting the shared DBSession should be done before any other Dropbox objects are 19 | used, perferrably in the UIApplication delegate. */ 20 | @interface DBSession : NSObject { 21 | MPOAuthCredentialConcreteStore* credentialStore; 22 | id delegate; 23 | } 24 | 25 | + (DBSession*)sharedSession; 26 | + (void)setSharedSession:(DBSession*)session; 27 | 28 | - (id)initWithConsumerKey:(NSString*)key consumerSecret:(NSString*)secret; 29 | - (BOOL)isLinked; // If not linked, you can only call loginWithEmail:password from the DBRestClient 30 | 31 | - (void)updateAccessToken:(NSString*)token accessTokenSecret:(NSString*)secret; 32 | - (void)unlink; 33 | 34 | @property (nonatomic, readonly) MPOAuthCredentialConcreteStore* credentialStore; 35 | @property (nonatomic, assign) id delegate; 36 | 37 | @end 38 | 39 | 40 | @protocol DBSessionDelegate 41 | 42 | - (void)sessionDidReceiveAuthorizationFailure:(DBSession*)session; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /DropboxSDK/DBSession.m: -------------------------------------------------------------------------------- 1 | // 2 | // DBSession.m 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 4/8/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | #import "DBSession.h" 10 | #import "MPOAuthCredentialConcreteStore.h" 11 | #import "MPOAuthSignatureParameter.h" 12 | 13 | 14 | NSString* kDBDropboxAPIHost = @"api.dropbox.com"; 15 | NSString* kDBDropboxAPIContentHost = @"api-content.dropbox.com"; 16 | NSString* kDBDropboxAPIVersion = @"0"; 17 | 18 | static DBSession* _sharedSession = nil; 19 | static NSString* kDBDropboxSavedCredentialsKey = @"kDBDropboxSavedCredentialsKey"; 20 | 21 | 22 | @interface DBSession () 23 | 24 | - (NSDictionary*)savedCredentials; 25 | - (void)saveCredentials:(NSDictionary*)credentials; 26 | - (void)clearSavedCredentials; 27 | 28 | @end 29 | 30 | 31 | @implementation DBSession 32 | 33 | + (DBSession*)sharedSession { 34 | return _sharedSession; 35 | } 36 | 37 | + (void)setSharedSession:(DBSession*)session { 38 | if (session == _sharedSession) return; 39 | [_sharedSession release]; 40 | _sharedSession = [session retain]; 41 | } 42 | 43 | - (id)initWithConsumerKey:(NSString*)key consumerSecret:(NSString*)secret { 44 | if ((self = [super init])) { 45 | 46 | NSMutableDictionary* credentials = 47 | [NSMutableDictionary dictionaryWithObjectsAndKeys: 48 | key, kMPOAuthCredentialConsumerKey, 49 | secret, kMPOAuthCredentialConsumerSecret, 50 | kMPOAuthSignatureMethodHMACSHA1, kMPOAuthSignatureMethod, nil]; 51 | 52 | NSDictionary* savedCredentials = [self savedCredentials]; 53 | if (savedCredentials != nil) { 54 | if ([key isEqualToString:[savedCredentials objectForKey:kMPOAuthCredentialConsumerKey]]) { 55 | 56 | [credentials setObject:[savedCredentials objectForKey:kMPOAuthCredentialAccessToken] 57 | forKey:kMPOAuthCredentialAccessToken]; 58 | [credentials setObject:[savedCredentials objectForKey:kMPOAuthCredentialAccessTokenSecret] 59 | forKey:kMPOAuthCredentialAccessTokenSecret]; 60 | } else { 61 | [self clearSavedCredentials]; 62 | } 63 | } 64 | 65 | credentialStore = [[MPOAuthCredentialConcreteStore alloc] initWithCredentials:credentials]; 66 | } 67 | return self; 68 | } 69 | 70 | - (void)dealloc { 71 | [credentialStore release]; 72 | [super dealloc]; 73 | } 74 | 75 | @synthesize credentialStore; 76 | @synthesize delegate; 77 | 78 | - (void)updateAccessToken:(NSString*)token accessTokenSecret:(NSString*)secret { 79 | credentialStore.accessToken = token; 80 | credentialStore.accessTokenSecret = secret; 81 | NSDictionary* credentials = [NSDictionary dictionaryWithObjectsAndKeys: 82 | credentialStore.consumerKey, kMPOAuthCredentialConsumerKey, 83 | credentialStore.accessToken, kMPOAuthCredentialAccessToken, 84 | credentialStore.accessTokenSecret, kMPOAuthCredentialAccessTokenSecret, 85 | nil]; 86 | [self saveCredentials:credentials]; 87 | } 88 | 89 | - (BOOL) isLinked { 90 | return credentialStore.accessToken != nil; 91 | } 92 | 93 | - (void)unlink { 94 | credentialStore.accessToken = nil; 95 | credentialStore.accessTokenSecret = nil; 96 | [self clearSavedCredentials]; 97 | } 98 | 99 | #pragma mark private methods 100 | 101 | - (NSDictionary*)savedCredentials { 102 | return [[NSUserDefaults standardUserDefaults] objectForKey:kDBDropboxSavedCredentialsKey]; 103 | } 104 | 105 | - (void)saveCredentials:(NSDictionary*)credentials { 106 | if (credentials == nil) return; 107 | 108 | [[NSUserDefaults standardUserDefaults] 109 | setObject:credentials forKey:kDBDropboxSavedCredentialsKey]; 110 | [[NSUserDefaults standardUserDefaults] synchronize]; 111 | } 112 | 113 | - (void)clearSavedCredentials { 114 | [[NSUserDefaults standardUserDefaults] removeObjectForKey:kDBDropboxSavedCredentialsKey]; 115 | } 116 | 117 | @end 118 | -------------------------------------------------------------------------------- /DropboxSDK/DropboxSDK.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DropboxSDK.h 3 | * DropboxSDK 4 | * 5 | * Created by Brian Smith on 7/13/10. 6 | * Copyright 2010 Dropbox, Inc. All rights reserved. 7 | * 8 | */ 9 | 10 | /* Import this file to get the most important header files imported */ 11 | #import "DBSession.h" 12 | #import "DBRestClient.h" 13 | #import "DBLoginController.h" 14 | #import "DBAccountInfo.h" 15 | #import "DBMetadata.h" 16 | #import "DBQuota.h" 17 | #import "DBError.h" 18 | #import "NSString+Dropbox.h" 19 | -------------------------------------------------------------------------------- /DropboxSDK/JSON/JSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /** 31 | @mainpage A strict JSON parser and generator for Objective-C 32 | 33 | JSON (JavaScript Object Notation) is a lightweight data-interchange 34 | format. This framework provides two apis for parsing and generating 35 | JSON. One standard object-based and a higher level api consisting of 36 | categories added to existing Objective-C classes. 37 | 38 | Learn more on the http://code.google.com/p/json-framework project site. 39 | 40 | This framework does its best to be as strict as possible, both in what it 41 | accepts and what it generates. For example, it does not support trailing commas 42 | in arrays or objects. Nor does it support embedded comments, or 43 | anything else not in the JSON specification. This is considered a feature. 44 | 45 | */ 46 | 47 | #import "SBJSON.h" 48 | #import "NSObject+SBJSON.h" 49 | #import "NSString+SBJSON.h" 50 | 51 | -------------------------------------------------------------------------------- /DropboxSDK/JSON/NSObject+SBJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | 32 | 33 | /** 34 | @brief Adds JSON generation to Foundation classes 35 | 36 | This is a category on NSObject that adds methods for returning JSON representations 37 | of standard objects to the objects themselves. This means you can call the 38 | -JSONRepresentation method on an NSArray object and it'll do what you want. 39 | */ 40 | @interface NSObject (NSObject_SBJSON) 41 | 42 | /** 43 | @brief Returns a string containing the receiver encoded as a JSON fragment. 44 | 45 | This method is added as a category on NSObject but is only actually 46 | supported for the following objects: 47 | @li NSDictionary 48 | @li NSArray 49 | @li NSString 50 | @li NSNumber (also used for booleans) 51 | @li NSNull 52 | 53 | @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. 54 | */ 55 | - (NSString *)JSONFragment; 56 | 57 | /** 58 | @brief Returns a string containing the receiver encoded in JSON. 59 | 60 | This method is added as a category on NSObject but is only actually 61 | supported for the following objects: 62 | @li NSDictionary 63 | @li NSArray 64 | */ 65 | - (NSString *)JSONRepresentation; 66 | 67 | @end 68 | 69 | -------------------------------------------------------------------------------- /DropboxSDK/JSON/NSObject+SBJSON.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import "NSObject+SBJSON.h" 31 | #import "SBJsonWriter.h" 32 | 33 | @implementation NSObject (NSObject_SBJSON) 34 | 35 | - (NSString *)JSONFragment { 36 | SBJsonWriter *jsonWriter = [SBJsonWriter new]; 37 | NSString *json = [jsonWriter stringWithFragment:self]; 38 | if (!json) 39 | NSLog(@"-JSONFragment failed. Error trace is: %@", [jsonWriter errorTrace]); 40 | [jsonWriter release]; 41 | return json; 42 | } 43 | 44 | - (NSString *)JSONRepresentation { 45 | SBJsonWriter *jsonWriter = [SBJsonWriter new]; 46 | NSString *json = [jsonWriter stringWithObject:self]; 47 | if (!json) 48 | NSLog(@"-JSONRepresentation failed. Error trace is: %@", [jsonWriter errorTrace]); 49 | [jsonWriter release]; 50 | return json; 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /DropboxSDK/JSON/NSString+SBJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | 32 | /** 33 | @brief Adds JSON parsing methods to NSString 34 | 35 | This is a category on NSString that adds methods for parsing the target string. 36 | */ 37 | @interface NSString (NSString_SBJSON) 38 | 39 | 40 | /** 41 | @brief Returns the object represented in the receiver, or nil on error. 42 | 43 | Returns a a scalar object represented by the string's JSON fragment representation. 44 | 45 | @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. 46 | */ 47 | - (id)JSONFragmentValue; 48 | 49 | /** 50 | @brief Returns the NSDictionary or NSArray represented by the current string's JSON representation. 51 | 52 | Returns the dictionary or array represented in the receiver, or nil on error. 53 | 54 | Returns the NSDictionary or NSArray represented by the current string's JSON representation. 55 | */ 56 | - (id)JSONValue; 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /DropboxSDK/JSON/NSString+SBJSON.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007-2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import "NSString+SBJSON.h" 31 | #import "SBJsonParser.h" 32 | 33 | @implementation NSString (NSString_SBJSON) 34 | 35 | - (id)JSONFragmentValue 36 | { 37 | SBJsonParser *jsonParser = [SBJsonParser new]; 38 | id repr = [jsonParser fragmentWithString:self]; 39 | if (!repr) 40 | NSLog(@"-JSONFragmentValue failed. Error trace is: %@", [jsonParser errorTrace]); 41 | [jsonParser release]; 42 | return repr; 43 | } 44 | 45 | - (id)JSONValue 46 | { 47 | SBJsonParser *jsonParser = [SBJsonParser new]; 48 | id repr = [jsonParser objectWithString:self]; 49 | if (!repr) 50 | NSLog(@"-JSONValue failed. Error trace is: %@", [jsonParser errorTrace]); 51 | [jsonParser release]; 52 | return repr; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /DropboxSDK/JSON/SBJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007-2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | #import "SBJsonParser.h" 32 | #import "SBJsonWriter.h" 33 | 34 | /** 35 | @brief Facade for SBJsonWriter/SBJsonParser. 36 | 37 | Requests are forwarded to instances of SBJsonWriter and SBJsonParser. 38 | */ 39 | @interface SBJSON : SBJsonBase { 40 | 41 | @private 42 | SBJsonParser *jsonParser; 43 | SBJsonWriter *jsonWriter; 44 | } 45 | 46 | 47 | /// Return the fragment represented by the given string 48 | - (id)fragmentWithString:(NSString*)jsonrep 49 | error:(NSError**)error; 50 | 51 | /// Return the object represented by the given string 52 | - (id)objectWithString:(NSString*)jsonrep 53 | error:(NSError**)error; 54 | 55 | /// Parse the string and return the represented object (or scalar) 56 | - (id)objectWithString:(id)value 57 | allowScalar:(BOOL)x 58 | error:(NSError**)error; 59 | 60 | 61 | /// Return JSON representation of an array or dictionary 62 | - (NSString*)stringWithObject:(id)value 63 | error:(NSError**)error; 64 | 65 | /// Return JSON representation of any legal JSON value 66 | - (NSString*)stringWithFragment:(id)value 67 | error:(NSError**)error; 68 | 69 | /// Return JSON representation (or fragment) for the given object 70 | - (NSString*)stringWithObject:(id)value 71 | allowScalar:(BOOL)x 72 | error:(NSError**)error; 73 | 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /DropboxSDK/JSON/SBJsonBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | 32 | extern NSString * SBJSONErrorDomain; 33 | 34 | 35 | enum { 36 | EUNSUPPORTED = 1, 37 | EPARSENUM, 38 | EPARSE, 39 | EFRAGMENT, 40 | ECTRL, 41 | EUNICODE, 42 | EDEPTH, 43 | EESCAPE, 44 | ETRAILCOMMA, 45 | ETRAILGARBAGE, 46 | EEOF, 47 | EINPUT 48 | }; 49 | 50 | /** 51 | @brief Common base class for parsing & writing. 52 | 53 | This class contains the common error-handling code and option between the parser/writer. 54 | */ 55 | @interface SBJsonBase : NSObject { 56 | NSMutableArray *errorTrace; 57 | 58 | @protected 59 | NSUInteger depth, maxDepth; 60 | } 61 | 62 | /** 63 | @brief The maximum recursing depth. 64 | 65 | Defaults to 512. If the input is nested deeper than this the input will be deemed to be 66 | malicious and the parser returns nil, signalling an error. ("Nested too deep".) You can 67 | turn off this security feature by setting the maxDepth value to 0. 68 | */ 69 | @property NSUInteger maxDepth; 70 | 71 | /** 72 | @brief Return an error trace, or nil if there was no errors. 73 | 74 | Note that this method returns the trace of the last method that failed. 75 | You need to check the return value of the call you're making to figure out 76 | if the call actually failed, before you know call this method. 77 | */ 78 | @property(copy,readonly) NSArray* errorTrace; 79 | 80 | /// @internal for use in subclasses to add errors to the stack trace 81 | - (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str; 82 | 83 | /// @internal for use in subclasess to clear the error before a new parsing attempt 84 | - (void)clearErrorTrace; 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /DropboxSDK/JSON/SBJsonBase.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import "SBJsonBase.h" 31 | NSString * SBJSONErrorDomain = @"org.brautaset.JSON.ErrorDomain"; 32 | 33 | 34 | @implementation SBJsonBase 35 | 36 | @synthesize errorTrace; 37 | @synthesize maxDepth; 38 | 39 | - (id)init { 40 | self = [super init]; 41 | if (self) 42 | self.maxDepth = 512; 43 | return self; 44 | } 45 | 46 | - (void)dealloc { 47 | [errorTrace release]; 48 | [super dealloc]; 49 | } 50 | 51 | - (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str { 52 | NSDictionary *userInfo; 53 | if (!errorTrace) { 54 | errorTrace = [NSMutableArray new]; 55 | userInfo = [NSDictionary dictionaryWithObject:str forKey:NSLocalizedDescriptionKey]; 56 | 57 | } else { 58 | userInfo = [NSDictionary dictionaryWithObjectsAndKeys: 59 | str, NSLocalizedDescriptionKey, 60 | [errorTrace lastObject], NSUnderlyingErrorKey, 61 | nil]; 62 | } 63 | 64 | NSError *error = [NSError errorWithDomain:SBJSONErrorDomain code:code userInfo:userInfo]; 65 | 66 | [self willChangeValueForKey:@"errorTrace"]; 67 | [errorTrace addObject:error]; 68 | [self didChangeValueForKey:@"errorTrace"]; 69 | } 70 | 71 | - (void)clearErrorTrace { 72 | [self willChangeValueForKey:@"errorTrace"]; 73 | [errorTrace release]; 74 | errorTrace = nil; 75 | [self didChangeValueForKey:@"errorTrace"]; 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /DropboxSDK/JSON/SBJsonParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | #import "SBJsonBase.h" 32 | 33 | /** 34 | @brief Options for the parser class. 35 | 36 | This exists so the SBJSON facade can implement the options in the parser without having to re-declare them. 37 | */ 38 | @protocol SBJsonParser 39 | 40 | /** 41 | @brief Return the object represented by the given string. 42 | 43 | Returns the object represented by the passed-in string or nil on error. The returned object can be 44 | a string, number, boolean, null, array or dictionary. 45 | 46 | @param repr the json string to parse 47 | */ 48 | - (id)objectWithString:(NSString *)repr; 49 | 50 | @end 51 | 52 | 53 | /** 54 | @brief The JSON parser class. 55 | 56 | JSON is mapped to Objective-C types in the following way: 57 | 58 | @li Null -> NSNull 59 | @li String -> NSMutableString 60 | @li Array -> NSMutableArray 61 | @li Object -> NSMutableDictionary 62 | @li Boolean -> NSNumber (initialised with -initWithBool:) 63 | @li Number -> NSDecimalNumber 64 | 65 | Since Objective-C doesn't have a dedicated class for boolean values, these turns into NSNumber 66 | instances. These are initialised with the -initWithBool: method, and 67 | round-trip back to JSON properly. (They won't silently suddenly become 0 or 1; they'll be 68 | represented as 'true' and 'false' again.) 69 | 70 | JSON numbers turn into NSDecimalNumber instances, 71 | as we can thus avoid any loss of precision. (JSON allows ridiculously large numbers.) 72 | 73 | */ 74 | @interface SBJsonParser : SBJsonBase { 75 | 76 | @private 77 | const char *c; 78 | } 79 | 80 | @end 81 | 82 | // don't use - exists for backwards compatibility with 2.1.x only. Will be removed in 2.3. 83 | @interface SBJsonParser (Private) 84 | - (id)fragmentWithString:(id)repr; 85 | @end 86 | 87 | 88 | -------------------------------------------------------------------------------- /DropboxSDK/JSON/SBJsonWriter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | #import "SBJsonBase.h" 32 | 33 | /** 34 | @brief Options for the writer class. 35 | 36 | This exists so the SBJSON facade can implement the options in the writer without having to re-declare them. 37 | */ 38 | @protocol SBJsonWriter 39 | 40 | /** 41 | @brief Whether we are generating human-readable (multiline) JSON. 42 | 43 | Set whether or not to generate human-readable JSON. The default is NO, which produces 44 | JSON without any whitespace. (Except inside strings.) If set to YES, generates human-readable 45 | JSON with linebreaks after each array value and dictionary key/value pair, indented two 46 | spaces per nesting level. 47 | */ 48 | @property BOOL humanReadable; 49 | 50 | /** 51 | @brief Whether or not to sort the dictionary keys in the output. 52 | 53 | If this is set to YES, the dictionary keys in the JSON output will be in sorted order. 54 | (This is useful if you need to compare two structures, for example.) The default is NO. 55 | */ 56 | @property BOOL sortKeys; 57 | 58 | /** 59 | @brief Return JSON representation (or fragment) for the given object. 60 | 61 | Returns a string containing JSON representation of the passed in value, or nil on error. 62 | If nil is returned and @p error is not NULL, @p *error can be interrogated to find the cause of the error. 63 | 64 | @param value any instance that can be represented as a JSON fragment 65 | 66 | */ 67 | - (NSString*)stringWithObject:(id)value; 68 | 69 | @end 70 | 71 | 72 | /** 73 | @brief The JSON writer class. 74 | 75 | Objective-C types are mapped to JSON types in the following way: 76 | 77 | @li NSNull -> Null 78 | @li NSString -> String 79 | @li NSArray -> Array 80 | @li NSDictionary -> Object 81 | @li NSNumber (-initWithBool:) -> Boolean 82 | @li NSNumber -> Number 83 | 84 | In JSON the keys of an object must be strings. NSDictionary keys need 85 | not be, but attempting to convert an NSDictionary with non-string keys 86 | into JSON will throw an exception. 87 | 88 | NSNumber instances created with the +initWithBool: method are 89 | converted into the JSON boolean "true" and "false" values, and vice 90 | versa. Any other NSNumber instances are converted to a JSON number the 91 | way you would expect. 92 | 93 | */ 94 | @interface SBJsonWriter : SBJsonBase { 95 | 96 | @private 97 | BOOL sortKeys, humanReadable; 98 | } 99 | 100 | @end 101 | 102 | // don't use - exists for backwards compatibility. Will be removed in 2.3. 103 | @interface SBJsonWriter (Private) 104 | - (NSString*)stringWithFragment:(id)value; 105 | @end 106 | 107 | /** 108 | @brief Allows generation of JSON for otherwise unsupported classes. 109 | 110 | If you have a custom class that you want to create a JSON representation for you can implement 111 | this method in your class. It should return a representation of your object defined 112 | in terms of objects that can be translated into JSON. For example, a Person 113 | object might implement it like this: 114 | 115 | @code 116 | - (id)jsonProxyObject { 117 | return [NSDictionary dictionaryWithObjectsAndKeys: 118 | name, @"name", 119 | phone, @"phone", 120 | email, @"email", 121 | nil]; 122 | } 123 | @endcode 124 | 125 | */ 126 | @interface NSObject (SBProxyForJson) 127 | - (id)proxyForJson; 128 | @end 129 | 130 | -------------------------------------------------------------------------------- /DropboxSDK/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Dropbox (Evenflow, Inc.), http://getdropbox.com/ 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/Crypto/Base64Transcoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Base64Transcoder.h 3 | * Base64Test 4 | * 5 | * Created by Jonathan Wight on Tue Mar 18 2003. 6 | * Copyright (c) 2003 Toxic Software. All rights reserved. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all 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 24 | * THE SOFTWARE. 25 | * 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | extern size_t EstimateBas64EncodedDataSize(size_t inDataSize); 32 | extern size_t EstimateBas64DecodedDataSize(size_t inDataSize); 33 | 34 | extern bool Base64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize); 35 | extern bool Base64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize); 36 | 37 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPDebug.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPDebug.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 09.02.06. 6 | // Copyright 2009 matrixPointer. All rights reserved. 7 | // 8 | 9 | #ifdef DEBUG 10 | #define MPLog(...) NSLog(__VA_ARGS__) 11 | #else 12 | #define MPLog(...) do { } while (0) 13 | #endif 14 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuth.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuth.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.13. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | #import 13 | #import 14 | #import 15 | #import 16 | #import 17 | #import 18 | #import 19 | #import 20 | #import 21 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthAPI.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthAPI.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MPOAuthCredentialStore.h" 11 | #import "MPOAuthParameterFactory.h" 12 | 13 | extern NSString * const MPOAuthNotificationAccessTokenReceived; 14 | extern NSString * const MPOAuthNotificationAccessTokenRejected; 15 | extern NSString * const MPOAuthNotificationAccessTokenRefreshed; 16 | extern NSString * const MPOAuthNotificationOAuthCredentialsReady; 17 | extern NSString * const MPOAuthNotificationErrorHasOccurred; 18 | 19 | extern NSString * const MPOAuthCredentialRequestTokenKey; 20 | extern NSString * const MPOAuthCredentialRequestTokenSecretKey; 21 | extern NSString * const MPOAuthCredentialAccessTokenKey; 22 | extern NSString * const MPOAuthCredentialAccessTokenSecretKey; 23 | extern NSString * const MPOAuthCredentialSessionHandleKey; 24 | 25 | extern NSString * const MPOAuthTokenRefreshDateDefaultsKey; 26 | 27 | typedef enum { 28 | MPOAuthSignatureSchemePlainText, 29 | MPOAuthSignatureSchemeHMACSHA1, 30 | MPOAuthSignatureSchemeRSASHA1 31 | } MPOAuthSignatureScheme; 32 | 33 | typedef enum { 34 | MPOAuthAuthenticationStateUnauthenticated = 0, 35 | MPOAuthAuthenticationStateAuthenticating = 1, 36 | MPOAuthAuthenticationStateAuthenticated = 2 37 | } MPOAuthAuthenticationState; 38 | 39 | @protocol MPOAuthAPIInternalClient 40 | @end 41 | 42 | @class MPOAuthAuthenticationMethod; 43 | 44 | @interface MPOAuthAPI : NSObject { 45 | @private 46 | id credentials_; 47 | NSURL *baseURL_; 48 | NSURL *authenticationURL_; 49 | MPOAuthAuthenticationMethod *authenticationMethod_; 50 | MPOAuthSignatureScheme signatureScheme_; 51 | NSMutableArray *activeLoaders_; 52 | MPOAuthAuthenticationState oauthAuthenticationState_; 53 | } 54 | 55 | @property (nonatomic, readonly, retain) id credentials; 56 | @property (nonatomic, readonly, retain) NSURL *baseURL; 57 | @property (nonatomic, readonly, retain) NSURL *authenticationURL; 58 | @property (nonatomic, readwrite, retain) MPOAuthAuthenticationMethod *authenticationMethod; 59 | @property (nonatomic, readwrite, assign) MPOAuthSignatureScheme signatureScheme; 60 | 61 | @property (nonatomic, readonly, assign) MPOAuthAuthenticationState authenticationState; 62 | 63 | 64 | - (id)initWithCredentials:(NSDictionary *)inCredentials andBaseURL:(NSURL *)inURL; 65 | - (id)initWithCredentials:(NSDictionary *)inCredentials authenticationURL:(NSURL *)inAuthURL andBaseURL:(NSURL *)inBaseURL; 66 | - (id)initWithCredentials:(NSDictionary *)inCredentials authenticationURL:(NSURL *)inAuthURL andBaseURL:(NSURL *)inBaseURL autoStart:(BOOL)aFlag; 67 | 68 | - (void)authenticate; 69 | - (BOOL)isAuthenticated; 70 | 71 | - (void)performMethod:(NSString *)inMethod withTarget:(id)inTarget andAction:(SEL)inAction; 72 | - (void)performMethod:(NSString *)inMethod atURL:(NSURL *)inURL withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction; 73 | - (void)performPOSTMethod:(NSString *)inMethod atURL:(NSURL *)inURL withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction; 74 | - (void)performURLRequest:(NSURLRequest *)inRequest withTarget:(id)inTarget andAction:(SEL)inAction; 75 | 76 | - (NSData *)dataForMethod:(NSString *)inMethod; 77 | - (NSData *)dataForMethod:(NSString *)inMethod withParameters:(NSArray *)inParameters; 78 | - (NSData *)dataForURL:(NSURL *)inURL andMethod:(NSString *)inMethod withParameters:(NSArray *)inParameters; 79 | 80 | - (id)credentialNamed:(NSString *)inCredentialName; 81 | - (void)setCredential:(id)inCredential withName:(NSString *)inName; 82 | - (void)removeCredentialNamed:(NSString *)inName; 83 | 84 | - (void)discardCredentials; 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthAPIRequestLoader.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthAPIRequestLoader.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | extern NSString * const MPOAuthNotificationRequestTokenReceived; 12 | extern NSString * const MPOAuthNotificationRequestTokenRejected; 13 | extern NSString * const MPOAuthNotificationAccessTokenReceived; 14 | extern NSString * const MPOAuthNotificationAccessTokenRejected; 15 | extern NSString * const MPOAuthNotificationAccessTokenRefreshed; 16 | extern NSString * const MPOAuthNotificationErrorHasOccurred; 17 | 18 | @protocol MPOAuthCredentialStore; 19 | @protocol MPOAuthParameterFactory; 20 | 21 | @class MPOAuthURLRequest; 22 | @class MPOAuthURLResponse; 23 | @class MPOAuthCredentialConcreteStore; 24 | 25 | @interface MPOAuthAPIRequestLoader : NSObject { 26 | MPOAuthCredentialConcreteStore *_credentials; 27 | MPOAuthURLRequest *_oauthRequest; 28 | MPOAuthURLResponse *_oauthResponse; 29 | NSMutableData *_dataBuffer; 30 | NSString *_dataAsString; 31 | NSError *_error; 32 | id _target; 33 | SEL _action; 34 | } 35 | 36 | @property (nonatomic, readwrite, retain) id credentials; 37 | @property (nonatomic, readwrite, retain) MPOAuthURLRequest *oauthRequest; 38 | @property (nonatomic, readwrite, retain) MPOAuthURLResponse *oauthResponse; 39 | @property (nonatomic, readonly, retain) NSData *data; 40 | @property (nonatomic, readonly, retain) NSString *responseString; 41 | @property (nonatomic, readwrite, assign) id target; 42 | @property (nonatomic, readwrite, assign) SEL action; 43 | 44 | - (id)initWithURL:(NSURL *)inURL; 45 | - (id)initWithRequest:(MPOAuthURLRequest *)inRequest; 46 | 47 | - (void)loadSynchronously:(BOOL)inSynchronous; 48 | 49 | @end 50 | 51 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthAuthenticationMethod.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthAuthenticationMethod.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 09.12.19. 6 | // Copyright 2009 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | extern NSString * const MPOAuthAccessTokenURLKey; 12 | 13 | @class MPOAuthAPI; 14 | 15 | @interface MPOAuthAuthenticationMethod : NSObject { 16 | MPOAuthAPI *oauthAPI_; 17 | NSURL *oauthGetAccessTokenURL_; 18 | NSTimer *refreshTimer_; 19 | } 20 | 21 | @property (nonatomic, readwrite, assign) MPOAuthAPI *oauthAPI; 22 | @property (nonatomic, readwrite, retain) NSURL *oauthGetAccessTokenURL; 23 | 24 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL; 25 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL withConfiguration:(NSDictionary *)inConfig; 26 | - (void)authenticate; 27 | 28 | - (void)setTokenRefreshInterval:(NSTimeInterval)inTimeInterval; 29 | - (void)refreshAccessToken; 30 | @end 31 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthAuthenticationMethod.m: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthAuthenticationMethod.m 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 09.12.19. 6 | // Copyright 2009 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import "MPOAuthAuthenticationMethod.h" 10 | #import "MPOAuthAuthenticationMethodOAuth.h" 11 | #import "MPOAuthCredentialConcreteStore.h" 12 | #import "MPURLRequestParameter.h" 13 | 14 | #import "NSURL+MPURLParameterAdditions.h" 15 | 16 | NSString * const MPOAuthAccessTokenURLKey = @"MPOAuthAccessTokenURL"; 17 | 18 | @interface MPOAuthAuthenticationMethod () 19 | @property (nonatomic, readwrite, retain) NSTimer *refreshTimer; 20 | 21 | + (Class)_authorizationMethodClassForURL:(NSURL *)inBaseURL withConfiguration:(NSDictionary **)outConfig; 22 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL withConfiguration:(NSDictionary *)inConfig; 23 | - (void)_automaticallyRefreshAccessToken:(NSTimer *)inTimer; 24 | @end 25 | 26 | @implementation MPOAuthAuthenticationMethod 27 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL { 28 | return [self initWithAPI:inAPI forURL:inURL withConfiguration:nil]; 29 | } 30 | 31 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL withConfiguration:(NSDictionary *)inConfig { 32 | if ([[self class] isEqual:[MPOAuthAuthenticationMethod class]]) { 33 | NSDictionary *configuration = nil; 34 | Class methodClass = [[self class] _authorizationMethodClassForURL:inURL withConfiguration:&configuration]; 35 | [self release]; 36 | 37 | self = [[methodClass alloc] initWithAPI:inAPI forURL:inURL withConfiguration:configuration]; 38 | } else if (self = [super init]) { 39 | self.oauthAPI = inAPI; 40 | } 41 | 42 | return self; 43 | } 44 | 45 | - (oneway void)dealloc { 46 | self.oauthAPI = nil; 47 | self.oauthGetAccessTokenURL = nil; 48 | 49 | [self.refreshTimer invalidate]; 50 | self.refreshTimer = nil; 51 | 52 | [super dealloc]; 53 | } 54 | 55 | @synthesize oauthAPI = oauthAPI_; 56 | @synthesize oauthGetAccessTokenURL = oauthGetAccessTokenURL_; 57 | @synthesize refreshTimer = refreshTimer_; 58 | 59 | #pragma mark - 60 | 61 | + (Class)_authorizationMethodClassForURL:(NSURL *)inBaseURL withConfiguration:(NSDictionary **)outConfig { 62 | Class methodClass = [MPOAuthAuthenticationMethodOAuth class]; 63 | NSString *oauthConfigPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"oauthAutoConfig" ofType:@"plist"]; 64 | NSDictionary *oauthConfigDictionary = [NSDictionary dictionaryWithContentsOfFile:oauthConfigPath]; 65 | 66 | for ( NSString *domainString in [oauthConfigDictionary keyEnumerator]) { 67 | if ([inBaseURL domainMatches:domainString]) { 68 | NSDictionary *oauthConfig = [oauthConfigDictionary objectForKey:domainString]; 69 | 70 | NSArray *requestedMethods = [oauthConfig objectForKey:@"MPOAuthAuthenticationPreferredMethods"]; 71 | NSString *requestedMethod = nil; 72 | for (requestedMethod in requestedMethods) { 73 | Class requestedMethodClass = NSClassFromString(requestedMethod); 74 | 75 | if (requestedMethodClass) { 76 | methodClass = requestedMethodClass; 77 | } 78 | break; 79 | } 80 | 81 | if (requestedMethod) { 82 | *outConfig = [oauthConfig objectForKey:requestedMethod]; 83 | } else { 84 | *outConfig = oauthConfig; 85 | } 86 | 87 | break; 88 | } 89 | } 90 | 91 | return methodClass; 92 | } 93 | 94 | #pragma mark - 95 | 96 | - (void)authenticate { 97 | [NSException raise:@"Not Implemented" format:@"All subclasses of MPOAuthAuthenticationMethod are required to implement -authenticate"]; 98 | } 99 | 100 | - (void)setTokenRefreshInterval:(NSTimeInterval)inTimeInterval { 101 | if (!self.refreshTimer && inTimeInterval > 0.0) { 102 | self.refreshTimer = [NSTimer scheduledTimerWithTimeInterval:inTimeInterval target:self selector:@selector(_automaticallyRefreshAccessToken:) userInfo:nil repeats:YES]; 103 | } 104 | } 105 | 106 | - (void)refreshAccessToken { 107 | MPURLRequestParameter *sessionHandleParameter = nil; 108 | MPOAuthCredentialConcreteStore *credentials = (MPOAuthCredentialConcreteStore *)[self.oauthAPI credentials]; 109 | 110 | if (credentials.sessionHandle) { 111 | sessionHandleParameter = [[MPURLRequestParameter alloc] init]; 112 | sessionHandleParameter.name = @"oauth_session_handle"; 113 | sessionHandleParameter.value = credentials.sessionHandle; 114 | } 115 | 116 | [self.oauthAPI performMethod:nil 117 | atURL:self.oauthGetAccessTokenURL 118 | withParameters:sessionHandleParameter ? [NSArray arrayWithObject:sessionHandleParameter] : nil 119 | withTarget:nil 120 | andAction:nil]; 121 | 122 | [sessionHandleParameter release]; 123 | } 124 | 125 | #pragma mark - 126 | 127 | - (void)_automaticallyRefreshAccessToken:(NSTimer *)inTimer { 128 | [self refreshAccessToken]; 129 | } 130 | 131 | @end 132 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthAuthenticationMethodOAuth.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthAuthenticationMethodOAuth.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 09.12.19. 6 | // Copyright 2009 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MPOAuthAuthenticationMethod.h" 11 | #import "MPOAuthAPI.h" 12 | #import "MPOAuthAPIRequestLoader.h" 13 | 14 | extern NSString * const MPOAuthNotificationRequestTokenReceived; 15 | extern NSString * const MPOAuthNotificationRequestTokenRejected; 16 | 17 | @protocol MPOAuthAuthenticationMethodOAuthDelegate; 18 | 19 | @interface MPOAuthAuthenticationMethodOAuth : MPOAuthAuthenticationMethod { 20 | NSURL *oauthRequestTokenURL_; 21 | NSURL *oauthAuthorizeTokenURL_; 22 | BOOL oauth10aModeActive_; 23 | 24 | id delegate_; 25 | } 26 | 27 | @property (nonatomic, readwrite, assign) id delegate; 28 | 29 | @property (nonatomic, readwrite, retain) NSURL *oauthRequestTokenURL; 30 | @property (nonatomic, readwrite, retain) NSURL *oauthAuthorizeTokenURL; 31 | 32 | - (void)authenticate; 33 | 34 | @end 35 | 36 | @protocol MPOAuthAuthenticationMethodOAuthDelegate 37 | - (NSURL *)callbackURLForCompletedUserAuthorization; 38 | - (BOOL)automaticallyRequestAuthenticationFromURL:(NSURL *)inAuthURL withCallbackURL:(NSURL *)inCallbackURL; 39 | 40 | @optional 41 | - (NSString *)oauthVerifierForCompletedUserAuthorization; 42 | - (void)authenticationDidFailWithError:(NSError *)error; 43 | @end 44 | 45 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthConnection.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthConnection.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol MPOAuthCredentialStore; 12 | @protocol MPOAuthParameterFactory; 13 | 14 | @class MPOAuthURLRequest; 15 | @class MPOAuthURLResponse; 16 | @class MPOAuthCredentialConcreteStore; 17 | 18 | @interface MPOAuthConnection : NSURLConnection { 19 | @private 20 | MPOAuthCredentialConcreteStore *_credentials; 21 | } 22 | 23 | @property (nonatomic, readonly) id credentials; 24 | 25 | + (MPOAuthConnection *)connectionWithRequest:(MPOAuthURLRequest *)inRequest delegate:(id)inDelegate credentials:(NSObject *)inCredentials; 26 | + (NSData *)sendSynchronousRequest:(MPOAuthURLRequest *)inRequest usingCredentials:(NSObject *)inCredentials returningResponse:(MPOAuthURLResponse **)outResponse error:(NSError **)inError; 27 | - (id)initWithRequest:(MPOAuthURLRequest *)inRequest delegate:(id)inDelegate credentials:(NSObject *)inCredentials; 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthConnection.m: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthConnection.m 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import "MPOAuthConnection.h" 10 | #import "MPOAuthURLRequest.h" 11 | #import "MPOAuthURLResponse.h" 12 | #import "MPOAuthParameterFactory.h" 13 | #import "MPOAuthCredentialConcreteStore.h" 14 | 15 | @interface MPOAuthURLResponse () 16 | @property (nonatomic, readwrite, retain) NSURLResponse *urlResponse; 17 | @property (nonatomic, readwrite, retain) NSDictionary *oauthParameters; 18 | @end 19 | 20 | @implementation MPOAuthConnection 21 | 22 | + (MPOAuthConnection *)connectionWithRequest:(MPOAuthURLRequest *)inRequest delegate:(id)inDelegate credentials:(NSObject *)inCredentials { 23 | MPOAuthConnection *aConnection = [[MPOAuthConnection alloc] initWithRequest:inRequest delegate:inDelegate credentials:inCredentials]; 24 | return [aConnection autorelease]; 25 | } 26 | 27 | + (NSData *)sendSynchronousRequest:(MPOAuthURLRequest *)inRequest usingCredentials:(NSObject *)inCredentials returningResponse:(MPOAuthURLResponse **)outResponse error:(NSError **)inError { 28 | [inRequest addParameters:[inCredentials oauthParameters]]; 29 | NSURLRequest *urlRequest = [inRequest urlRequestSignedWithSecret:[inCredentials signingKey] usingMethod:[inCredentials signatureMethod]]; 30 | NSURLResponse *urlResponse = nil; 31 | NSData *responseData = [self sendSynchronousRequest:urlRequest returningResponse:&urlResponse error:inError]; 32 | MPOAuthURLResponse *oauthResponse = [[[MPOAuthURLResponse alloc] init] autorelease]; 33 | oauthResponse.urlResponse = urlResponse; 34 | *outResponse = oauthResponse; 35 | 36 | return responseData; 37 | } 38 | 39 | - (id)initWithRequest:(MPOAuthURLRequest *)inRequest delegate:(id)inDelegate credentials:(NSObject *)inCredentials { 40 | [inRequest addParameters:[inCredentials oauthParameters]]; 41 | NSURLRequest *urlRequest = [inRequest urlRequestSignedWithSecret:[inCredentials signingKey] usingMethod:[inCredentials signatureMethod]]; 42 | if (self = [super initWithRequest:urlRequest delegate:inDelegate]) { 43 | _credentials = [inCredentials retain]; 44 | } 45 | return self; 46 | } 47 | 48 | - (oneway void)dealloc { 49 | [_credentials release]; 50 | 51 | [super dealloc]; 52 | } 53 | 54 | @synthesize credentials = _credentials; 55 | 56 | #pragma mark - 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthCredentiaIConcreteStore+KeychainAdditionsMac.m: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthCredentialConcreteStore+TokenAdditionsMac.m 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.13. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import "MPOAuthCredentialConcreteStore+KeychainAdditions.h" 10 | 11 | #if !TARGET_OS_IPHONE || (TARGET_IPHONE_SIMULATOR && !__IPHONE_3_0) 12 | 13 | @interface MPOAuthCredentialConcreteStore (KeychainAdditionsMac) 14 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName returningItem:(SecKeychainItemRef *)outKeychainItemRef; 15 | @end 16 | 17 | @implementation MPOAuthCredentialConcreteStore (KeychainAdditions) 18 | 19 | - (void)addToKeychainUsingName:(NSString *)inName andValue:(NSString *)inValue { 20 | NSString *serverName = [self.baseURL host]; 21 | NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier]; 22 | NSString *securityDomain = [self.authenticationURL host]; 23 | NSString *uniqueName = [NSString stringWithFormat:@"%@.%@", bundleID, inName]; 24 | SecKeychainItemRef existingKeychainItem = NULL; 25 | 26 | if ([self findValueFromKeychainUsingName:inName returningItem:&existingKeychainItem]) { 27 | // This is MUCH easier than updating the item attributes/data 28 | SecKeychainItemDelete(existingKeychainItem); 29 | } 30 | 31 | SecKeychainAddInternetPassword(NULL /* default keychain */, 32 | [serverName length], [serverName UTF8String], 33 | [securityDomain length], [securityDomain UTF8String], 34 | [uniqueName length], [uniqueName UTF8String], /* account name */ 35 | 0, NULL, /* path */ 36 | 0, 37 | 'oaut' /* OAuth, not an official OSType code */, 38 | kSecAuthenticationTypeDefault, 39 | [inValue length], [inValue UTF8String], 40 | NULL); 41 | } 42 | 43 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName { 44 | return [self findValueFromKeychainUsingName:inName returningItem:NULL]; 45 | } 46 | 47 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName returningItem:(SecKeychainItemRef *)outKeychainItemRef { 48 | NSString *foundPassword = nil; 49 | NSString *serverName = [self.baseURL host]; 50 | NSString *securityDomain = [self.authenticationURL host]; 51 | NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier]; 52 | NSString *uniqueName = [NSString stringWithFormat:@"%@.%@", bundleID, inName]; 53 | 54 | UInt32 passwordLength = 0; 55 | const char *passwordString = NULL; 56 | 57 | OSStatus status = SecKeychainFindInternetPassword(NULL /* default keychain */, 58 | [serverName length], [serverName UTF8String], 59 | [securityDomain length], [securityDomain UTF8String], 60 | [uniqueName length], [uniqueName UTF8String], 61 | 0, NULL, /* path */ 62 | 0, 63 | kSecProtocolTypeAny, 64 | kSecAuthenticationTypeAny, 65 | (UInt32 *)&passwordLength, 66 | (void **)&passwordString, 67 | outKeychainItemRef); 68 | 69 | if (status == noErr && passwordLength) { 70 | NSData *passwordStringData = [NSData dataWithBytes:passwordString length:passwordLength]; 71 | foundPassword = [[NSString alloc] initWithData:passwordStringData encoding:NSUTF8StringEncoding]; 72 | } 73 | 74 | return [foundPassword autorelease]; 75 | } 76 | 77 | - (void)removeValueFromKeychainUsingName:(NSString *)inName { 78 | SecKeychainItemRef aKeychainItem = NULL; 79 | 80 | [self findValueFromKeychainUsingName:inName returningItem:&aKeychainItem]; 81 | 82 | if (aKeychainItem) { 83 | SecKeychainItemDelete(aKeychainItem); 84 | } 85 | } 86 | 87 | @end 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthCredentialConcreteStore+KeychainAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthCredentialConcreteStore+TokenAdditionsMac.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.13. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MPOAuthCredentialConcreteStore.h" 11 | 12 | @interface MPOAuthCredentialConcreteStore (KeychainAdditions) 13 | 14 | - (void)addToKeychainUsingName:(NSString *)inName andValue:(NSString *)inValue; 15 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName; 16 | - (void)removeValueFromKeychainUsingName:(NSString *)inName; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthCredentialConcreteStore+KeychainAdditionsiPhone.m: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthCredentialConcreteStore+TokenAdditionsiPhone.m 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.13. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import "MPOAuthCredentialConcreteStore+KeychainAdditions.h" 10 | #import 11 | 12 | #if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || __IPHONE_3_0) 13 | 14 | @interface MPOAuthCredentialConcreteStore (TokenAdditionsiPhone) 15 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName returningItem:(NSDictionary **)outKeychainItemRef; 16 | @end 17 | 18 | @implementation MPOAuthCredentialConcreteStore (KeychainAdditions) 19 | 20 | - (void)addToKeychainUsingName:(NSString *)inName andValue:(NSString *)inValue { 21 | NSString *serverName = [self.baseURL host]; 22 | NSString *securityDomain = [self.authenticationURL host]; 23 | // NSString *itemID = [NSString stringWithFormat:@"%@.oauth.%@", [[NSBundle mainBundle] bundleIdentifier], inName]; 24 | NSDictionary *searchDictionary = nil; 25 | NSDictionary *keychainItemAttributeDictionary = [NSDictionary dictionaryWithObjectsAndKeys: (id)kSecClassInternetPassword, kSecClass, 26 | securityDomain, kSecAttrSecurityDomain, 27 | serverName, kSecAttrServer, 28 | inName, kSecAttrAccount, 29 | kSecAttrAuthenticationTypeDefault, kSecAttrAuthenticationType, 30 | [NSNumber numberWithUnsignedLongLong:'oaut'], kSecAttrType, 31 | [inValue dataUsingEncoding:NSUTF8StringEncoding], kSecValueData, 32 | nil]; 33 | 34 | 35 | if ([self findValueFromKeychainUsingName:inName returningItem:&searchDictionary]) { 36 | NSMutableDictionary *updateDictionary = [keychainItemAttributeDictionary mutableCopy]; 37 | [updateDictionary removeObjectForKey:(id)kSecClass]; 38 | 39 | SecItemUpdate((CFDictionaryRef)keychainItemAttributeDictionary, (CFDictionaryRef)updateDictionary); 40 | [updateDictionary release]; 41 | } else { 42 | OSStatus success = SecItemAdd( (CFDictionaryRef)keychainItemAttributeDictionary, NULL); 43 | 44 | if (success == errSecNotAvailable) { 45 | [NSException raise:@"Keychain Not Available" format:@"Keychain Access Not Currently Available"]; 46 | } else if (success == errSecDuplicateItem) { 47 | [NSException raise:@"Keychain duplicate item exception" format:@"Item already exists for %@", keychainItemAttributeDictionary]; 48 | } 49 | } 50 | } 51 | 52 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName { 53 | return [self findValueFromKeychainUsingName:inName returningItem:NULL]; 54 | } 55 | 56 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName returningItem:(NSDictionary **)outKeychainItemRef { 57 | NSString *foundPassword = nil; 58 | NSString *serverName = [self.baseURL host]; 59 | NSString *securityDomain = [self.authenticationURL host]; 60 | NSDictionary *attributesDictionary = nil; 61 | NSData *foundValue = nil; 62 | OSStatus status = noErr; 63 | // NSString *itemID = [NSString stringWithFormat:@"%@.oauth.%@", [[NSBundle mainBundle] bundleIdentifier], inName]; 64 | 65 | NSMutableDictionary *searchDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:(id)kSecClassInternetPassword, (id)kSecClass, 66 | securityDomain, (id)kSecAttrSecurityDomain, 67 | serverName, (id)kSecAttrServer, 68 | inName, (id)kSecAttrAccount, 69 | (id)kSecMatchLimitOne, (id)kSecMatchLimit, 70 | (id)kCFBooleanTrue, (id)kSecReturnData, 71 | (id)kCFBooleanTrue, (id)kSecReturnAttributes, 72 | (id)kCFBooleanTrue, (id)kSecReturnPersistentRef, 73 | nil]; 74 | 75 | status = SecItemCopyMatching((CFDictionaryRef)searchDictionary, (CFTypeRef *)&attributesDictionary); 76 | foundValue = [attributesDictionary objectForKey:(id)kSecValueData]; 77 | if (outKeychainItemRef) { 78 | *outKeychainItemRef = attributesDictionary; 79 | } 80 | 81 | if (status == noErr && foundValue) { 82 | foundPassword = [[NSString alloc] initWithData:foundValue encoding:NSUTF8StringEncoding]; 83 | } 84 | 85 | return [foundPassword autorelease]; 86 | } 87 | 88 | - (void)removeValueFromKeychainUsingName:(NSString *)inName { 89 | NSString *serverName = [self.baseURL host]; 90 | NSString *securityDomain = [self.authenticationURL host]; 91 | 92 | NSMutableDictionary *searchDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: (id)kSecClassInternetPassword, (id)kSecClass, 93 | securityDomain, (id)kSecAttrSecurityDomain, 94 | serverName, (id)kSecAttrServer, 95 | inName, (id)kSecAttrAccount, 96 | nil]; 97 | 98 | OSStatus success = SecItemDelete((CFDictionaryRef)searchDictionary); 99 | 100 | if (success == errSecNotAvailable) { 101 | [NSException raise:@"Keychain Not Available" format:@"Keychain Access Not Currently Available"]; 102 | } else if (success == errSecParam) { 103 | [NSException raise:@"Keychain parameter error" format:@"One or more parameters passed to the function were not valid from %@", searchDictionary]; 104 | } else if (success == errSecAllocate) { 105 | [NSException raise:@"Keychain memory error" format:@"Failed to allocate memory"]; 106 | } 107 | 108 | } 109 | 110 | @end 111 | 112 | #endif TARGET_OS_IPHONE 113 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthCredentialConcreteStore.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthCredentialConcreteStore.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.11. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MPOAuthCredentialStore.h" 11 | #import "MPOAuthParameterFactory.h" 12 | 13 | @interface MPOAuthCredentialConcreteStore : NSObject { 14 | NSMutableDictionary *store_; 15 | NSURL *baseURL_; 16 | NSURL *authenticationURL_; 17 | } 18 | 19 | @property (nonatomic, readonly, retain) NSURL *baseURL; 20 | @property (nonatomic, readonly, retain) NSURL *authenticationURL; 21 | 22 | @property (nonatomic, readonly) NSString *tokenSecret; 23 | @property (nonatomic, readonly) NSString *signingKey; 24 | 25 | @property (nonatomic, readwrite, retain) NSString *requestToken; 26 | @property (nonatomic, readwrite, retain) NSString *requestTokenSecret; 27 | @property (nonatomic, readwrite, retain) NSString *accessToken; 28 | @property (nonatomic, readwrite, retain) NSString *accessTokenSecret; 29 | 30 | @property (nonatomic, readwrite, retain) NSString *sessionHandle; 31 | 32 | - (id)initWithCredentials:(NSDictionary *)inCredential; 33 | - (id)initWithCredentials:(NSDictionary *)inCredentials forBaseURL:(NSURL *)inBaseURL; 34 | - (id)initWithCredentials:(NSDictionary *)inCredentials forBaseURL:(NSURL *)inBaseURL withAuthenticationURL:(NSURL *)inAuthenticationURL; 35 | 36 | - (void)setCredential:(id)inCredential withName:(NSString *)inName; 37 | - (void)removeCredentialNamed:(NSString *)inName; 38 | 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthCredentialStore.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthCredentialStore.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.06. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | extern NSString *kMPOAuthCredentialConsumerKey; 10 | extern NSString *kMPOAuthCredentialConsumerSecret; 11 | extern NSString *kMPOAuthCredentialUsername; 12 | extern NSString *kMPOAuthCredentialPassword; 13 | extern NSString *kMPOAuthCredentialRequestToken; 14 | extern NSString *kMPOAuthCredentialRequestTokenSecret; 15 | extern NSString *kMPOAuthCredentialAccessToken; 16 | extern NSString *kMPOAuthCredentialAccessTokenSecret; 17 | extern NSString *kMPOAuthCredentialSessionHandle; 18 | extern NSString *kMPOAuthCredentialRealm; 19 | 20 | @protocol MPOAuthCredentialStore 21 | 22 | @property (nonatomic, readonly) NSString *consumerKey; 23 | @property (nonatomic, readonly) NSString *consumerSecret; 24 | @property (nonatomic, readonly) NSString *username; 25 | @property (nonatomic, readonly) NSString *password; 26 | @property (nonatomic, readonly, retain) NSString *requestToken; 27 | @property (nonatomic, readonly, retain) NSString *requestTokenSecret; 28 | @property (nonatomic, readonly, retain) NSString *accessToken; 29 | @property (nonatomic, readonly, retain) NSString *accessTokenSecret; 30 | 31 | - (NSString *)credentialNamed:(NSString *)inCredentialName; 32 | - (void)discardOAuthCredentials; 33 | @end 34 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthParameterFactory.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthParameterFactory.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.06. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | extern NSString *kMPOAuthSignatureMethod; 10 | 11 | @class MPURLRequestParameter; 12 | 13 | @protocol MPOAuthParameterFactory 14 | 15 | @property (nonatomic, readwrite, retain) NSString *signatureMethod; 16 | @property (nonatomic, readonly) NSString *signingKey; 17 | @property (nonatomic, readonly) NSString *timestamp; 18 | 19 | - (NSArray *)oauthParameters; 20 | 21 | - (MPURLRequestParameter *)oauthConsumerKeyParameter; 22 | - (MPURLRequestParameter *)oauthTokenParameter; 23 | - (MPURLRequestParameter *)oauthSignatureMethodParameter; 24 | - (MPURLRequestParameter *)oauthTimestampParameter; 25 | - (MPURLRequestParameter *)oauthNonceParameter; 26 | - (MPURLRequestParameter *)oauthVersionParameter; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthSignatureParameter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthSignatureParameter.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.07. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MPURLRequestParameter.h" 11 | 12 | #define kMPOAuthSignatureMethodPlaintext @"PLAINTEXT" 13 | #define kMPOAuthSignatureMethodHMACSHA1 @"HMAC-SHA1" 14 | #define kMPOAuthSignatureMethodRSASHA1 @"RSA-SHA1" 15 | 16 | @class MPOAuthURLRequest; 17 | 18 | @interface MPOAuthSignatureParameter : MPURLRequestParameter { 19 | 20 | } 21 | 22 | + (NSString *)signatureBaseStringUsingParameterString:(NSString *)inParameterString forRequest:(MPOAuthURLRequest *)inRequest; 23 | + (NSString *)HMAC_SHA1SignatureForText:(NSString *)inText usingSecret:(NSString *)inSecret; 24 | 25 | - (id)initWithText:(NSString *)inText andSecret:(NSString *)inSecret forRequest:(MPOAuthURLRequest *)inRequest usingMethod:(NSString *)inMethod; 26 | 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthSignatureParameter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthSignatureParameter.m 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.07. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import "MPOAuthSignatureParameter.h" 10 | #import "MPOAuthURLRequest.h" 11 | #import "NSString+URLEscapingAdditions.h" 12 | #import "NSURL+MPURLParameterAdditions.h" 13 | 14 | #import 15 | #include "Base64Transcoder.h" 16 | 17 | @interface MPOAuthSignatureParameter () 18 | - (id)initUsingHMAC_SHA1WithText:(NSString *)inText andSecret:(NSString *)inSecret forRequest:(MPOAuthURLRequest *)inRequest; 19 | @end 20 | 21 | @implementation MPOAuthSignatureParameter 22 | 23 | + (NSString *)signatureBaseStringUsingParameterString:(NSString *)inParameterString forRequest:(MPOAuthURLRequest *)inRequest { 24 | return [NSString stringWithFormat:@"%@&%@&%@", [inRequest HTTPMethod], 25 | [[inRequest.url absoluteNormalizedString] stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding], 26 | [inParameterString stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 27 | } 28 | 29 | + (NSString *)HMAC_SHA1SignatureForText:(NSString *)inText usingSecret:(NSString *)inSecret { 30 | NSData *secretData = [inSecret dataUsingEncoding:NSUTF8StringEncoding]; 31 | NSData *textData = [inText dataUsingEncoding:NSUTF8StringEncoding]; 32 | unsigned char result[CC_SHA1_DIGEST_LENGTH]; 33 | 34 | CCHmacContext hmacContext; 35 | bzero(&hmacContext, sizeof(CCHmacContext)); 36 | CCHmacInit(&hmacContext, kCCHmacAlgSHA1, secretData.bytes, secretData.length); 37 | CCHmacUpdate(&hmacContext, textData.bytes, textData.length); 38 | CCHmacFinal(&hmacContext, result); 39 | 40 | //Base64 Encoding 41 | char base64Result[32]; 42 | size_t theResultLength = 32; 43 | Base64EncodeData(result, 20, base64Result, &theResultLength); 44 | NSData *theData = [NSData dataWithBytes:base64Result length:theResultLength]; 45 | NSString *base64EncodedResult = [[[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding] autorelease]; 46 | 47 | return base64EncodedResult; 48 | } 49 | 50 | - (id)initWithText:(NSString *)inText andSecret:(NSString *)inSecret forRequest:(MPOAuthURLRequest *)inRequest usingMethod:(NSString *)inMethod { 51 | if ([inMethod isEqual:kMPOAuthSignatureMethodHMACSHA1]) { 52 | self = [self initUsingHMAC_SHA1WithText:inText andSecret:inSecret forRequest:inRequest]; 53 | } else if ([inMethod isEqualToString:kMPOAuthSignatureMethodPlaintext]) { 54 | if (self = [super init]) { 55 | self.name = @"oauth_signature"; 56 | self.value = inSecret; 57 | } 58 | } else { 59 | [self release]; 60 | self = nil; 61 | [NSException raise:@"Unsupported Signature Method" format:@"The signature method \"%@\" is not currently support by MPOAuthConnection", inMethod]; 62 | } 63 | 64 | return self; 65 | } 66 | 67 | - (id)initUsingHMAC_SHA1WithText:(NSString *)inText andSecret:(NSString *)inSecret forRequest:(MPOAuthURLRequest *)inRequest { 68 | if (self = [super init]) { 69 | NSString *signatureBaseString = [MPOAuthSignatureParameter signatureBaseStringUsingParameterString:inText forRequest:inRequest]; 70 | 71 | self.name = @"oauth_signature"; 72 | self.value = [MPOAuthSignatureParameter HMAC_SHA1SignatureForText:signatureBaseString usingSecret:inSecret]; 73 | } 74 | return self; 75 | } 76 | 77 | - (oneway void)dealloc { 78 | [super dealloc]; 79 | } 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthURLRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthURLRequest.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface MPOAuthURLRequest : NSObject { 13 | @private 14 | NSURL *_url; 15 | NSString *_httpMethod; 16 | NSURLRequest *_urlRequest; 17 | NSMutableArray *_parameters; 18 | } 19 | 20 | @property (nonatomic, readwrite, retain) NSURL *url; 21 | @property (nonatomic, readwrite, retain) NSString *HTTPMethod; 22 | @property (nonatomic, readonly, retain) NSURLRequest *urlRequest; 23 | @property (nonatomic, readwrite, retain) NSMutableArray *parameters; 24 | 25 | - (id)initWithURL:(NSURL *)inURL andParameters:(NSArray *)parameters; 26 | - (id)initWithURLRequest:(NSURLRequest *)inRequest; 27 | 28 | - (void)addParameters:(NSArray *)inParameters; 29 | 30 | - (NSMutableURLRequest*)urlRequestSignedWithSecret:(NSString *)inSecret usingMethod:(NSString *)inScheme; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthURLRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthURLRequest.m 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import "MPOAuthURLRequest.h" 10 | #import "MPURLRequestParameter.h" 11 | #import "MPOAuthSignatureParameter.h" 12 | #import "MPDebug.h" 13 | 14 | #import "NSURL+MPURLParameterAdditions.h" 15 | #import "NSString+URLEscapingAdditions.h" 16 | 17 | @interface MPOAuthURLRequest () 18 | @property (nonatomic, readwrite, retain) NSURLRequest *urlRequest; 19 | @end 20 | 21 | @implementation MPOAuthURLRequest 22 | 23 | - (id)initWithURL:(NSURL *)inURL andParameters:(NSArray *)inParameters { 24 | if (self = [super init]) { 25 | self.url = inURL; 26 | _parameters = inParameters ? [inParameters mutableCopy] : [[NSMutableArray alloc] initWithCapacity:10]; 27 | self.HTTPMethod = @"GET"; 28 | } 29 | return self; 30 | } 31 | 32 | - (id)initWithURLRequest:(NSURLRequest *)inRequest { 33 | if (self = [super init]) { 34 | self.url = [[inRequest URL] urlByRemovingQuery]; 35 | self.parameters = [[MPURLRequestParameter parametersFromString:[[inRequest URL] query]] mutableCopy]; 36 | self.HTTPMethod = [inRequest HTTPMethod]; 37 | } 38 | return self; 39 | } 40 | 41 | - (oneway void)dealloc { 42 | self.url = nil; 43 | self.HTTPMethod = nil; 44 | self.urlRequest = nil; 45 | self.parameters = nil; 46 | 47 | [super dealloc]; 48 | } 49 | 50 | @synthesize url = _url; 51 | @synthesize HTTPMethod = _httpMethod; 52 | @synthesize urlRequest = _urlRequest; 53 | @synthesize parameters = _parameters; 54 | 55 | #pragma mark - 56 | 57 | - (NSMutableURLRequest*)urlRequestSignedWithSecret:(NSString *)inSecret usingMethod:(NSString *)inScheme { 58 | [self.parameters sortUsingSelector:@selector(compare:)]; 59 | 60 | NSMutableURLRequest *aRequest = [[NSMutableURLRequest alloc] init]; 61 | NSMutableString *parameterString = [[NSMutableString alloc] initWithString:[MPURLRequestParameter parameterStringForParameters:self.parameters]]; 62 | MPOAuthSignatureParameter *signatureParameter = [[MPOAuthSignatureParameter alloc] initWithText:parameterString andSecret:inSecret forRequest:self usingMethod:inScheme]; 63 | [parameterString appendFormat:@"&%@", [signatureParameter URLEncodedParameterString]]; 64 | 65 | [aRequest setHTTPMethod:self.HTTPMethod]; 66 | 67 | if ([[self HTTPMethod] isEqualToString:@"GET"] && [self.parameters count]) { 68 | NSString *urlString = [NSString stringWithFormat:@"%@?%@", [self.url absoluteString], parameterString]; 69 | //MPLog( @"urlString - %@", urlString); 70 | 71 | [aRequest setURL:[NSURL URLWithString:urlString]]; 72 | } else if ([[self HTTPMethod] isEqualToString:@"POST"]) { 73 | NSData *postData = [parameterString dataUsingEncoding:NSUTF8StringEncoding]; 74 | //MPLog(@"urlString - %@", self.url); 75 | //MPLog(@"postDataString - %@", parameterString); 76 | 77 | [aRequest setURL:self.url]; 78 | [aRequest setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"]; 79 | [aRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 80 | [aRequest setHTTPBody:postData]; 81 | } else { 82 | [NSException raise:@"UnhandledHTTPMethodException" format:@"The requested HTTP method, %@, is not supported", self.HTTPMethod]; 83 | } 84 | 85 | [parameterString release]; 86 | [signatureParameter release]; 87 | 88 | self.urlRequest = aRequest; 89 | [aRequest release]; 90 | 91 | return aRequest; 92 | } 93 | 94 | #pragma mark - 95 | 96 | - (void)addParameters:(NSArray *)inParameters { 97 | [self.parameters addObjectsFromArray:inParameters]; 98 | } 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthURLResponse.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthURLResponse.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface MPOAuthURLResponse : NSObject { 13 | NSURLResponse *_urlResponse; 14 | NSDictionary *_oauthParameters; 15 | } 16 | 17 | @property (nonatomic, readonly, retain) NSURLResponse *urlResponse; 18 | @property (nonatomic, readonly, retain) NSDictionary *oauthParameters; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPOAuthURLResponse.m: -------------------------------------------------------------------------------- 1 | // 2 | // MPOAuthURLResponse.m 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import "MPOAuthURLResponse.h" 10 | 11 | @interface MPOAuthURLResponse () 12 | @property (nonatomic, readwrite, retain) NSURLResponse *urlResponse; 13 | @property (nonatomic, readwrite, retain) NSDictionary *oauthParameters; 14 | @end 15 | 16 | @implementation MPOAuthURLResponse 17 | 18 | - (id)init { 19 | if (self = [super init]) { 20 | 21 | } 22 | return self; 23 | } 24 | 25 | - (oneway void)dealloc { 26 | self.urlResponse = nil; 27 | self.oauthParameters = nil; 28 | 29 | [super dealloc]; 30 | } 31 | 32 | @synthesize urlResponse = _urlResponse; 33 | @synthesize oauthParameters = _oauthParameters; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPURLRequestParameter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MPURLParameter.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface MPURLRequestParameter : NSObject { 13 | NSString *_name; 14 | NSString *_value; 15 | } 16 | 17 | @property (nonatomic, readwrite, copy) NSString *name; 18 | @property (nonatomic, readwrite, copy) NSString *value; 19 | 20 | + (NSArray *)parametersFromString:(NSString *)inString; 21 | + (NSArray *)parametersFromDictionary:(NSDictionary *)inDictionary; 22 | + (NSDictionary *)parameterDictionaryFromString:(NSString *)inString; 23 | + (NSString *)parameterStringForParameters:(NSArray *)inParameters; 24 | + (NSString *)parameterStringForDictionary:(NSDictionary *)inParameterDictionary; 25 | 26 | - (id)initWithName:(NSString *)inName andValue:(NSString *)inValue; 27 | 28 | - (NSString *)URLEncodedParameterString; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/MPURLRequestParameter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MPURLParameter.m 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import "MPURLRequestParameter.h" 10 | #import "NSString+URLEscapingAdditions.h" 11 | 12 | @implementation MPURLRequestParameter 13 | 14 | + (NSArray *)parametersFromString:(NSString *)inString { 15 | NSMutableArray *foundParameters = [NSMutableArray arrayWithCapacity:10]; 16 | NSScanner *parameterScanner = [[NSScanner alloc] initWithString:inString]; 17 | NSString *name = nil; 18 | NSString *value = nil; 19 | MPURLRequestParameter *currentParameter = nil; 20 | 21 | while (![parameterScanner isAtEnd]) { 22 | name = nil; 23 | value = nil; 24 | 25 | [parameterScanner scanUpToString:@"=" intoString:&name]; 26 | [parameterScanner scanString:@"=" intoString:NULL]; 27 | [parameterScanner scanUpToString:@"&" intoString:&value]; 28 | [parameterScanner scanString:@"&" intoString:NULL]; 29 | 30 | currentParameter = [[MPURLRequestParameter alloc] init]; 31 | currentParameter.name = name; 32 | currentParameter.value = [value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 33 | 34 | [foundParameters addObject:currentParameter]; 35 | 36 | [currentParameter release]; 37 | } 38 | 39 | [parameterScanner release]; 40 | 41 | return foundParameters; 42 | } 43 | 44 | + (NSArray *)parametersFromDictionary:(NSDictionary *)inDictionary { 45 | NSMutableArray *parameterArray = [[NSMutableArray alloc] init]; 46 | MPURLRequestParameter *aURLParameter = nil; 47 | 48 | for (NSString *aKey in [inDictionary allKeys]) { 49 | aURLParameter = [[MPURLRequestParameter alloc] init]; 50 | aURLParameter.name = aKey; 51 | aURLParameter.value = [inDictionary objectForKey:aKey]; 52 | 53 | [parameterArray addObject:aURLParameter]; 54 | [aURLParameter release]; 55 | } 56 | 57 | return [parameterArray autorelease]; 58 | } 59 | 60 | + (NSDictionary *)parameterDictionaryFromString:(NSString *)inString { 61 | NSMutableDictionary *foundParameters = [NSMutableDictionary dictionaryWithCapacity:10]; 62 | if (inString) { 63 | NSScanner *parameterScanner = [[NSScanner alloc] initWithString:inString]; 64 | NSString *name = nil; 65 | NSString *value = nil; 66 | 67 | while (![parameterScanner isAtEnd]) { 68 | name = nil; 69 | value = nil; 70 | 71 | [parameterScanner scanUpToString:@"=" intoString:&name]; 72 | [parameterScanner scanString:@"=" intoString:NULL]; 73 | [parameterScanner scanUpToString:@"&" intoString:&value]; 74 | [parameterScanner scanString:@"&" intoString:NULL]; 75 | 76 | [foundParameters setObject:[value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] forKey:name]; 77 | } 78 | 79 | [parameterScanner release]; 80 | } 81 | return foundParameters; 82 | } 83 | 84 | + (NSString *)parameterStringForParameters:(NSArray *)inParameters { 85 | NSMutableString *queryString = [[NSMutableString alloc] init]; 86 | int i = 0; 87 | int parameterCount = [inParameters count]; 88 | MPURLRequestParameter *aParameter = nil; 89 | 90 | for (; i < parameterCount; i++) { 91 | aParameter = [inParameters objectAtIndex:i]; 92 | [queryString appendString:[aParameter URLEncodedParameterString]]; 93 | 94 | if (i < parameterCount - 1) { 95 | [queryString appendString:@"&"]; 96 | } 97 | } 98 | 99 | return [queryString autorelease]; 100 | } 101 | 102 | + (NSString *)parameterStringForDictionary:(NSDictionary *)inParameterDictionary { 103 | NSArray *parameters = [self parametersFromDictionary:inParameterDictionary]; 104 | NSString *queryString = [self parameterStringForParameters:parameters]; 105 | 106 | return queryString; 107 | } 108 | 109 | #pragma mark - 110 | 111 | - (id)init { 112 | if (self = [super init]) { 113 | 114 | } 115 | return self; 116 | } 117 | 118 | - (id)initWithName:(NSString *)inName andValue:(NSString *)inValue { 119 | if (self = [super init]) { 120 | self.name = inName; 121 | self.value = inValue; 122 | } 123 | return self; 124 | } 125 | 126 | - (oneway void)dealloc { 127 | self.name = nil; 128 | self.value = nil; 129 | 130 | [super dealloc]; 131 | } 132 | 133 | @synthesize name = _name; 134 | @synthesize value = _value; 135 | 136 | #pragma mark - 137 | 138 | - (NSString *)URLEncodedParameterString { 139 | return [NSString stringWithFormat:@"%@=%@", [self.name stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding], self.value ? [self.value stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding] : @""]; 140 | } 141 | 142 | #pragma mark - 143 | 144 | - (NSComparisonResult)compare:(id)inObject { 145 | NSComparisonResult result = [self.name compare:[(MPURLRequestParameter *)inObject name]]; 146 | 147 | if (result == NSOrderedSame) { 148 | result = [self.value compare:[(MPURLRequestParameter *)inObject value]]; 149 | } 150 | 151 | return result; 152 | } 153 | 154 | - (NSString *)description { 155 | return [NSString stringWithFormat:@"<%@: %p %@>", NSStringFromClass([self class]), self, [self URLEncodedParameterString]]; 156 | } 157 | 158 | @end 159 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/NSString+URLEscapingAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+URLEscapingAdditions.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.07. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface NSString (MPURLEscapingAdditions) 13 | 14 | - (BOOL)isIPAddress; 15 | - (NSString *)stringByAddingURIPercentEscapesUsingEncoding:(NSStringEncoding)inEncoding; 16 | 17 | @end 18 | 19 | @interface NSURL (MPURLEscapingAdditions) 20 | - (NSString *)stringByAddingURIPercentEscapesUsingEncoding:(NSStringEncoding)inEncoding; 21 | @end 22 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/NSString+URLEscapingAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+URLEscapingAdditions.m 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.07. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import "NSString+URLEscapingAdditions.h" 10 | 11 | 12 | @implementation NSString (MPURLEscapingAdditions) 13 | 14 | - (BOOL)isIPAddress { 15 | BOOL isIPAddress = NO; 16 | NSArray *components = [self componentsSeparatedByString:@"."]; 17 | NSCharacterSet *invalidCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"1234567890"] invertedSet]; 18 | 19 | if ([components count] == 4) { 20 | NSString *part1 = [components objectAtIndex:0]; 21 | NSString *part2 = [components objectAtIndex:1]; 22 | NSString *part3 = [components objectAtIndex:2]; 23 | NSString *part4 = [components objectAtIndex:3]; 24 | 25 | if ([part1 rangeOfCharacterFromSet:invalidCharacters].location == NSNotFound && 26 | [part2 rangeOfCharacterFromSet:invalidCharacters].location == NSNotFound && 27 | [part3 rangeOfCharacterFromSet:invalidCharacters].location == NSNotFound && 28 | [part4 rangeOfCharacterFromSet:invalidCharacters].location == NSNotFound ) { 29 | 30 | if ([part1 intValue] < 255 && 31 | [part2 intValue] < 255 && 32 | [part3 intValue] < 255 && 33 | [part4 intValue] < 255) { 34 | isIPAddress = YES; 35 | } 36 | } 37 | } 38 | 39 | return isIPAddress; 40 | } 41 | 42 | - (NSString *)stringByAddingURIPercentEscapesUsingEncoding:(NSStringEncoding)inEncoding { 43 | NSString *escapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 44 | (CFStringRef)self, 45 | NULL, 46 | (CFStringRef)@":/?=,!$&'()*+;[]@#", 47 | CFStringConvertNSStringEncodingToEncoding(inEncoding)); 48 | 49 | return [escapedString autorelease]; 50 | } 51 | 52 | @end 53 | 54 | @implementation NSURL (MPURLEscapingAdditions) 55 | 56 | - (NSString *)stringByAddingURIPercentEscapesUsingEncoding:(NSStringEncoding)inEncoding { 57 | return [[self absoluteString] stringByAddingURIPercentEscapesUsingEncoding:inEncoding]; 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/NSURL+MPURLParameterAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSURL+MPURLParameterAdditions.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.08. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface NSURL (MPURLParameterAdditions) 13 | 14 | - (NSURL *)urlByAddingParameters:(NSArray *)inParameters; 15 | - (NSURL *)urlByAddingParameterDictionary:(NSDictionary *)inParameters; 16 | - (NSURL *)urlByRemovingQuery; 17 | - (NSString *)absoluteNormalizedString; 18 | 19 | - (BOOL)domainMatches:(NSString *)inString; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/NSURL+MPURLParameterAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSURL+MPURLParameterAdditions.m 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.08. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import "NSURL+MPURLParameterAdditions.h" 10 | #import "MPURLRequestParameter.h" 11 | #import "NSString+URLEscapingAdditions.h" 12 | 13 | @implementation NSURL (MPURLParameterAdditions) 14 | 15 | - (NSURL *)urlByAddingParameters:(NSArray *)inParameters { 16 | NSMutableArray *parameters = [[NSMutableArray alloc] init]; 17 | NSString *queryString = [self query]; 18 | NSString *absoluteString = [self absoluteString]; 19 | NSRange parameterRange = [absoluteString rangeOfString:@"?"]; 20 | 21 | if (parameterRange.location != NSNotFound) { 22 | parameterRange.length = [absoluteString length] - parameterRange.location; 23 | [parameters addObjectsFromArray:[MPURLRequestParameter parametersFromString:queryString]]; 24 | absoluteString = [absoluteString substringToIndex:parameterRange.location]; 25 | } 26 | 27 | [parameters addObjectsFromArray:inParameters]; 28 | 29 | return [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", absoluteString, [MPURLRequestParameter parameterStringForParameters:[parameters autorelease]]]]; 30 | } 31 | 32 | - (NSURL *)urlByAddingParameterDictionary:(NSDictionary *)inParameterDictionary { 33 | NSMutableDictionary *parameterDictionary = [inParameterDictionary mutableCopy]; 34 | NSString *queryString = [self query]; 35 | NSString *absoluteString = [self absoluteString]; 36 | NSRange parameterRange = [absoluteString rangeOfString:@"?"]; 37 | NSURL *composedURL = self; 38 | 39 | if (parameterRange.location != NSNotFound) { 40 | parameterRange.length = [absoluteString length] - parameterRange.location; 41 | 42 | //[parameterDictionary addEntriesFromDictionary:inParameterDictionary]; 43 | [parameterDictionary addEntriesFromDictionary:[MPURLRequestParameter parameterDictionaryFromString:queryString]]; 44 | 45 | composedURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", [absoluteString substringToIndex:parameterRange.location], [MPURLRequestParameter parameterStringForDictionary:parameterDictionary]]]; 46 | } else if ([parameterDictionary count]) { 47 | composedURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", absoluteString, [MPURLRequestParameter parameterStringForDictionary:parameterDictionary]]]; 48 | } 49 | 50 | [parameterDictionary release]; 51 | 52 | return composedURL; 53 | } 54 | 55 | - (NSURL *)urlByRemovingQuery { 56 | NSURL *composedURL = self; 57 | NSString *absoluteString = [self absoluteString]; 58 | NSRange queryRange = [absoluteString rangeOfString:@"?"]; 59 | 60 | if (queryRange.location != NSNotFound) { 61 | NSString *urlSansQuery = [absoluteString substringToIndex:queryRange.location]; 62 | composedURL = [NSURL URLWithString:urlSansQuery]; 63 | } 64 | 65 | return composedURL; 66 | } 67 | 68 | - (NSString *)absoluteNormalizedString { 69 | NSString *normalizedString = [self absoluteString]; 70 | 71 | if ([[self path] length] == 0 && [[self query] length] == 0) { 72 | normalizedString = [NSString stringWithFormat:@"%@/", [self absoluteString]]; 73 | } 74 | 75 | return normalizedString; 76 | } 77 | 78 | - (BOOL)domainMatches:(NSString *)inString { 79 | BOOL matches = NO; 80 | 81 | NSString *domain = [self host]; 82 | matches = [domain isIPAddress] && [domain isEqualToString:inString]; 83 | 84 | int domainLength = [domain length]; 85 | int requestedDomainLength = [inString length]; 86 | 87 | if (!matches) { 88 | if (domainLength > requestedDomainLength) { 89 | matches = [domain rangeOfString:inString].location == (domainLength - requestedDomainLength); 90 | } else if (domainLength == (requestedDomainLength - 1)) { 91 | matches = ([inString compare:domain options:NSCaseInsensitiveSearch range:NSMakeRange(1, domainLength)] == NSOrderedSame); 92 | } 93 | } 94 | 95 | return matches; 96 | } 97 | 98 | @end 99 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/NSURLResponse+Encoding.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSURL+MPEncodingAdditions.h 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface NSURLResponse (EncodingAdditions) 13 | - (NSStringEncoding)encoding; 14 | @end 15 | -------------------------------------------------------------------------------- /DropboxSDK/MPOAuth/NSURLResponse+Encoding.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSURL+MPEncodingAdditions.m 3 | // MPOAuthConnection 4 | // 5 | // Created by Karl Adam on 08.12.05. 6 | // Copyright 2008 matrixPointer. All rights reserved. 7 | // 8 | 9 | #import "NSURLResponse+Encoding.h" 10 | 11 | 12 | @implementation NSURLResponse (EncodingAdditions) 13 | 14 | - (NSStringEncoding)encoding { 15 | NSStringEncoding encoding = NSUTF8StringEncoding; 16 | 17 | if ([self textEncodingName]) { 18 | CFStringEncoding cfStringEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)[self textEncodingName]); 19 | if (cfStringEncoding != kCFStringEncodingInvalidId) { 20 | encoding = CFStringConvertEncodingToNSStringEncoding(cfStringEncoding); 21 | } 22 | } 23 | 24 | return encoding; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /DropboxSDK/NSString+Dropbox.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Dropbox.h 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 7/19/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | 10 | @interface NSString (Dropbox) 11 | 12 | // This will take a path for a resource and normalize so you can compare paths 13 | - (NSString*)normalizedDropboxPath; 14 | 15 | // Normalizes both paths and compares them 16 | - (BOOL)isEqualToDropboxPath:(NSString*)otherPath; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /DropboxSDK/NSString+Dropbox.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Dropbox.m 3 | // DropboxSDK 4 | // 5 | // Created by Brian Smith on 7/19/10. 6 | // Copyright 2010 Dropbox, Inc. All rights reserved. 7 | // 8 | 9 | #import "NSString+Dropbox.h" 10 | 11 | 12 | @implementation NSString (Dropbox) 13 | 14 | - (NSString*)normalizedDropboxPath { 15 | NSString *lowercaseString = [self lowercaseString]; 16 | NSString *precomposedStringWithCanonicalMapping = [lowercaseString precomposedStringWithCanonicalMapping]; 17 | return precomposedStringWithCanonicalMapping; 18 | } 19 | 20 | - (BOOL)isEqualToDropboxPath:(NSString*)otherPath { 21 | return [[self normalizedDropboxPath] isEqualToString:[otherPath normalizedDropboxPath]]; 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /DropboxSDK/Resources/db_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/DropboxSDK/Resources/db_background.png -------------------------------------------------------------------------------- /DropboxSDK/Resources/db_create_account.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/DropboxSDK/Resources/db_create_account.png -------------------------------------------------------------------------------- /DropboxSDK/Resources/db_create_account@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/DropboxSDK/Resources/db_create_account@2x.png -------------------------------------------------------------------------------- /DropboxSDK/Resources/db_create_account_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/DropboxSDK/Resources/db_create_account_button.png -------------------------------------------------------------------------------- /DropboxSDK/Resources/db_create_account_button_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/DropboxSDK/Resources/db_create_account_button_down.png -------------------------------------------------------------------------------- /DropboxSDK/Resources/db_link_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/DropboxSDK/Resources/db_link_button.png -------------------------------------------------------------------------------- /DropboxSDK/Resources/db_link_button_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/DropboxSDK/Resources/db_link_button_down.png -------------------------------------------------------------------------------- /DropboxSDK/Resources/db_link_header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/DropboxSDK/Resources/db_link_header.png -------------------------------------------------------------------------------- /DropboxSDK/Resources/db_link_header@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/DropboxSDK/Resources/db_link_header@2x.png -------------------------------------------------------------------------------- /DropboxSDK/Resources/db_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/DropboxSDK/Resources/db_logo.png -------------------------------------------------------------------------------- /DropboxSDK/Resources/db_logo@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/DropboxSDK/Resources/db_logo@2x.png -------------------------------------------------------------------------------- /DropboxSync.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DropboxSync.xcodeproj/xcuserdata/jesse.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /DropboxSync.xcodeproj/xcuserdata/jesse.xcuserdatad/xcschemes/DropboxSync.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | 43 | 50 | 51 | 53 | 54 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /DropboxSync.xcodeproj/xcuserdata/jesse.xcuserdatad/xcschemes/Tests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 40 | 41 | 47 | 48 | 49 | 50 | 51 | 52 | 59 | 60 | 66 | 67 | 68 | 69 | 71 | 72 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /DropboxSync.xcodeproj/xcuserdata/jesse.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DropboxSync.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | Tests.xcscheme 13 | 14 | orderHint 15 | 1 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | C5ACA5AC1320D0F5000502D1 21 | 22 | primary 23 | 24 | 25 | D2AAC07D0554694100DB518D 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Hog Bay Software, http://www.hogbaysoftware.com 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | DropboxSync is designed to keep a local folder hierarchy on iOS synced with a Dropbox folder hierarchy. The goal is to work like Dropbox on other platforms… ie the client application works with files on the file system, and they are magically synced in the background. 2 | 3 | ## Operation 4 | 5 | Unfortunately DropboxSync can't be quite as magic from an application developers perspective as Dropbox on the Desktop. In particular you are responsible for controlling the sync process through calls to enqueueFolderSyncPathRequest after you've made local changes to files in a directory, or when you want to refresh a directory from the server. 6 | 7 | PathController maintains state on synced paths and fires notifications when those paths are modified as part of the sync process. PathController also provides a set of "Path Modifications" methods that fire those same events. The idea is that you can use those method when making your local filesystem notifications, and then your views can get a universal set of file changed notifications no matter if it's your code, or the sync code that's updating the paths. 8 | 9 | ## Requirements 10 | 11 | DropboxSync uses a slightly (DBRestClient>didParseMetadata) modified version of the Dropbox SDK that fixes a bug with wifi hotspot paywall pages. 12 | 13 | DropboxSync uses Coredata to store local metadata used by the sync process. 14 | 15 | ## Limitations 16 | 17 | DropboxSync doesn't handle local renaming of synced folders well. Renames are synced as Delete/Add on server. For files this works, but for directories there are no checks on place to see if server directories contents have been modified, and so a local rename will just delete those files. I just disable local folder rename in my app, a better solution would be to make to the Dropboxe API Rename command. 18 | 19 | ## Running Tests 20 | 21 | Before running tests you must set your application keys and dropbox password in PathControllerTests.h. You also need to copy the DropboxTestFolderFixture (in Tests) to you Dropbox account and then update PathControllerTests.h with that path. 22 | 23 | ## Basic usage 24 | 25 | // 1. Set Dropbox shared session with keys from app using API 26 | [DBSession setSharedSession:[[[DBSession alloc] initWithConsumerKey:CONSUMERKEY consumerSecret:CONSUMERSECRET] autorelease]]; 27 | 28 | // 2. Create path controller. 29 | PathController *pathController = [[PathController alloc] initWithLocalRoot:LOCAL_ROOT serverRoot:SERVER_ROOT pathMetadataStorePath:METADATA_STORE]; 30 | 31 | // 3. If isn't already linked then link 32 | if (!pathController.isLinked) { 33 | [pathController linkWithEmail:DROPBOX_ACCOUNT password:DROPBOX_PASSWORD]; 34 | } 35 | 36 | // 4. Sync top level (not recursive) local root with server root. 37 | [pathController enqueueFolderSyncPathRequest:pathController.localRoot]; 38 | -------------------------------------------------------------------------------- /Source/DeleteLocalPathOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // DeleteLocalPathOperation.h 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/11/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "PathOperation.h" 10 | #import "DropboxSDK.h" 11 | 12 | // 13 | // Operation to (safely, ie don't delete unsynced data) delete local path. 14 | // 15 | 16 | @interface DeleteLocalPathOperation : PathOperation { 17 | 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Source/DeleteLocalPathOperation.m: -------------------------------------------------------------------------------- 1 | // 2 | // DeleteLocalPathOperation.m 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/11/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "DeleteLocalPathOperation.h" 10 | #import "FolderSyncPathOperation.h" 11 | #import "PathController.h" 12 | #import "PathMetadata.h" 13 | 14 | @implementation DeleteLocalPathOperation 15 | 16 | - (void)main { 17 | [self deleteLocalPath]; 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Source/DeletePathOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // DeletePathOperation.h 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/11/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "PathOperation.h" 10 | 11 | // 12 | // Delete path on server. 13 | // 14 | 15 | @interface DeletePathOperation : PathOperation { 16 | 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Source/DeletePathOperation.m: -------------------------------------------------------------------------------- 1 | // 2 | // DeletePathOperation.m 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/11/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "DeletePathOperation.h" 10 | #import "PathController_Private.h" 11 | #import "PathController.h" 12 | 13 | @implementation DeletePathOperation 14 | 15 | - (BOOL)isDeleteOperation { 16 | return YES; 17 | } 18 | 19 | - (void)main { 20 | [self.client deletePath:[self.pathController localPathToServer:localPath]]; 21 | } 22 | 23 | - (void)restClient:(DBRestClient*)aClient deletedPath:(NSString *)aServerPath { 24 | [self.pathController deletePathMetadataForLocalPath:localPath]; 25 | self.createPathMetadataOnFinish = NO; 26 | [self finish]; 27 | } 28 | 29 | - (void)restClient:(DBRestClient*)aClient deletePathFailedWithError:(NSError*)error { 30 | [self retryWithError:error]; 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Source/DropboxSync_Prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #import 4 | #import 5 | #import "DropboxSDK.h" 6 | #endif -------------------------------------------------------------------------------- /Source/FolderSyncPathOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // LoadMetadataSyncPathOperation.h 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/7/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "PathOperation.h" 10 | 11 | // 12 | // This operation is responsible for syncing a folder (not recursive). It fetches server metadata, compares to local metadata 13 | // and schedules individual path operations as needed to complete the sync. This operation doesn't complete until all individual 14 | // operations have completed. 15 | // 16 | 17 | @interface FolderSyncPathOperation : PathOperation { 18 | BOOL loadedMetadata; 19 | BOOL needsCleanupSync; 20 | BOOL schedulingOperations; 21 | NSMutableSet *pathOperations; 22 | PathController *pathController; 23 | NSUInteger operationCount; 24 | } 25 | 26 | - (id)initWithPath:(NSString *)aLocalPath pathController:(PathController *)aPathController; 27 | 28 | @property (assign) BOOL needsCleanupSync; 29 | 30 | - (void)pathOperationFinished:(PathOperation *)aPathOperation; 31 | 32 | @end -------------------------------------------------------------------------------- /Source/GetPathOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // GetPathOperation.h 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/10/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "PathOperation.h" 10 | 11 | // 12 | // Get server file and add (or update) local. 13 | // 14 | 15 | @interface GetPathOperation : PathOperation { 16 | NSString *tempDownloadPath; 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Source/NSFileManager_Additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSFileManager_Additions.h 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 10/8/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | 10 | #import 11 | 12 | @interface NSFileManager (DropboxSyncAdditions) 13 | 14 | - (NSString *)tempDirectory; 15 | - (NSString *)tempDirectoryUnusedPath; 16 | - (BOOL)my_moveItemAtPath:(NSString *)fromPath toPath:(NSString *)toPath error:(NSError **)error; 17 | - (NSString *)conflictPathForPath:(NSString *)aPath error:(NSError **)error; 18 | - (NSString *)conflictPathForPath:(NSString *)aPath includeMessage:(BOOL)includeMessage error:(NSError **)error; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Source/NSFileManager_Additions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSFileManager_Additions.m 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 6/9/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | 10 | #import "NSFileManager_Additions.h" 11 | #import "NSString+Dropbox.h" 12 | #import "NSSet_Additions.h" 13 | 14 | @implementation NSFileManager (DropboxSyncAdditions) 15 | 16 | - (NSString *)tempDirectory { 17 | NSString *tempDirectory = NSTemporaryDirectory(); 18 | NSError *error; 19 | 20 | if (![self createDirectoryAtPath:tempDirectory withIntermediateDirectories:YES attributes:nil error:&error]) { 21 | NSLog(@"Unable to find or create temp directory:\n%@", error); 22 | } 23 | 24 | return tempDirectory; 25 | } 26 | 27 | - (NSString *)tempDirectoryUnusedPath { 28 | return [[self tempDirectory] stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]; 29 | } 30 | 31 | - (BOOL)my_moveItemAtPath:(NSString *)fromPath toPath:(NSString *)toPath error:(NSError **)error { 32 | if ([fromPath isEqualToDropboxPath:toPath]) { 33 | NSString *unusedPath = [self tempDirectoryUnusedPath]; 34 | if ([self moveItemAtPath:fromPath toPath:unusedPath error:error]) { 35 | if ([self moveItemAtPath:unusedPath toPath:toPath error:error]) { 36 | return YES; 37 | } 38 | } 39 | return NO; 40 | } else { 41 | return [self moveItemAtPath:fromPath toPath:toPath error:error]; 42 | } 43 | } 44 | 45 | - (NSString *)conflictPathForPath:(NSString *)aPath error:(NSError **)error { 46 | return [self conflictPathForPath:aPath includeMessage:YES error:error]; 47 | } 48 | 49 | - (NSString *)conflictPathForPath:(NSString *)aPath includeMessage:(BOOL)includeMessage error:(NSError **)error { 50 | NSString *directory = [aPath stringByDeletingLastPathComponent]; 51 | NSString *filename = [aPath lastPathComponent]; 52 | 53 | if (![self createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:error]) { 54 | return nil; 55 | } 56 | 57 | NSArray *normalizedContents = [[self contentsOfDirectoryAtPath:directory error:error] valueForKey:@"normalizedDropboxPath"]; 58 | NSSet *normalizedContentsSet = [NSSet setWithArray:normalizedContents]; 59 | NSString *conflictName = [normalizedContentsSet conflictNameForNameInNormalizedSet:filename includeMessage:includeMessage]; 60 | 61 | return [directory stringByAppendingPathComponent:conflictName]; 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /Source/NSSet_Additions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSSet_Additions.h 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 6/9/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | 10 | @interface NSSet (DropboxSyncAdditions) 11 | - (NSMutableSet *)setMinusSet:(NSSet *)aSet; 12 | - (NSMutableSet *)setIntersectingSet:(NSSet *)aSet; 13 | - (NSMutableSet *)setFilteredUsingPredicate:(NSPredicate *)aPredicate; 14 | - (NSString *)conflictNameForNameInNormalizedSet:(NSString *)name; 15 | - (NSString *)conflictNameForNameInNormalizedSet:(NSString *)name includeMessage:(BOOL)includeMessage; 16 | @end 17 | -------------------------------------------------------------------------------- /Source/NSSet_Additions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSSet_Additions.m 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 6/9/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "NSSet_Additions.h" 10 | #import "DropboxSDK.h" 11 | 12 | 13 | @implementation NSSet (DropboxSyncAdditions) 14 | 15 | - (NSMutableSet *)setMinusSet:(NSSet *)aSet { 16 | NSMutableSet *result = [[self mutableCopy] autorelease]; 17 | [result minusSet:aSet]; 18 | return result; 19 | } 20 | 21 | - (NSMutableSet *)setIntersectingSet:(NSSet *)aSet { 22 | NSMutableSet *result = [[self mutableCopy] autorelease]; 23 | [result intersectSet:aSet]; 24 | return result; 25 | } 26 | 27 | - (NSMutableSet *)setFilteredUsingPredicate:(NSPredicate *)aPredicate { 28 | NSMutableSet *result = [[self mutableCopy] autorelease]; 29 | [result filterUsingPredicate:aPredicate]; 30 | return result; 31 | } 32 | 33 | - (NSString *)conflictNameForNameInNormalizedSet:(NSString *)name { 34 | return [self conflictNameForNameInNormalizedSet:name includeMessage:YES]; 35 | } 36 | 37 | - (NSString *)conflictNameForNameInNormalizedSet:(NSString *)name includeMessage:(BOOL)includeMessage { 38 | NSString *base = [name stringByDeletingPathExtension]; 39 | NSString *extension = [name pathExtension]; 40 | 41 | if (includeMessage) { 42 | NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 43 | [dateFormatter setDateFormat:@"yyyy-MM-dd"]; 44 | base = [base stringByAppendingFormat:@" (%@'s conflicted copy %@)", [[UIDevice currentDevice] name], [dateFormatter stringFromDate:[NSDate date]], nil]; // use dropbox style 45 | } 46 | 47 | if ([extension length] > 0) { 48 | name = [base stringByAppendingPathExtension:extension]; 49 | } 50 | 51 | NSUInteger count = 1; 52 | while ([self containsObject:[name normalizedDropboxPath]]) { 53 | name = [base stringByAppendingFormat:@" %i", count++]; 54 | if ([extension length] > 0) { 55 | name = [name stringByAppendingPathExtension:extension]; 56 | } 57 | } 58 | 59 | return name; 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Source/PathControllerDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // PathControllerDelegate.h 3 | // DropboxLib 4 | // 5 | // Created by Jesse Grosjean on 3/7/11. 6 | // Copyright 2011 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | 10 | @protocol PathControllerDelegate 11 | 12 | // Return yes if the file should be synced, no if not. If not then a local empy placeholder file will be created 13 | // for the file and the path state will be set to PermanentPlaceholderPathState 14 | - (BOOL)shouldSyncFile:(NSString *)file; 15 | - (void)syncProgress:(CGFloat)progress fromPathController:(id)aPathController; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Source/PathController_Private.h: -------------------------------------------------------------------------------- 1 | // 2 | // PathController_Private.h 3 | // DropboxLib 4 | // 5 | // Created by Jesse Grosjean on 3/7/11. 6 | // Copyright 2011 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "PathController.h" 10 | 11 | @interface PathController (Private) 12 | 13 | - (NSString *)serverPathToLocal:(NSString *)serverPath; 14 | - (NSString *)localPathToServer:(NSString *)localPath; 15 | - (NSString *)localPathToNormalized:(NSString *)localPath; 16 | 17 | - (BOOL)saveState; 18 | - (void)setPathActivity:(PathActivity)aPathActivity forPath:(NSString *)aLocalPath; 19 | - (PathMetadata *)pathMetadataForLocalPath:(NSString *)localPath createNewLocalIfNeeded:(BOOL)createIfNeeded; 20 | - (void)deletePathMetadataForLocalPath:(NSString *)localPath; 21 | - (void)initManagedObjectContext; 22 | - (void)postQueuedPathChangedNotifications; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /Source/PathMetadata.h: -------------------------------------------------------------------------------- 1 | // 2 | // PathMetadata.h 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/7/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "PathController.h" 11 | 12 | // 13 | // Maintains persistent metadata about a paths sync state such as last sync date and last sync hash. 14 | // 15 | 16 | @class PathController; 17 | @class PathOperation; 18 | @class PathMetadata; 19 | 20 | @interface PathMetadata : NSManagedObject { 21 | PathState pathState; 22 | BOOL lastSyncIsDirectory; 23 | NSString *normalizedPath; 24 | NSError *pathError; 25 | } 26 | 27 | + (PathMetadata *)pathMetadataWithNormalizedName:(NSString *)aNormalizedName managedObjectContext:(NSManagedObjectContext *)aManagedObjectContext; 28 | 29 | @property(readonly) BOOL isRoot; 30 | @property(readonly) NSString *normalizedName; 31 | @property(readonly) NSString *normalizedPath; // transient 32 | @property(readonly) PathController *pathController; // transient 33 | @property(nonatomic, retain) NSError *pathError; // transient 34 | 35 | #pragma mark - 36 | #pragma mark Children 37 | 38 | @property(readonly) PathMetadata* parent; 39 | @property(nonatomic, retain) NSSet* children; 40 | @property(readonly) NSSet* allDescendantsWithSelf; 41 | 42 | #pragma mark - 43 | #pragma mark Last Sync Metadata 44 | 45 | @property(nonatomic, assign) PathState pathState; 46 | @property(nonatomic, retain) NSString *lastSyncName; 47 | @property(nonatomic, retain) NSDate *lastSyncDate; 48 | @property(nonatomic, retain) NSString *lastSyncHash; 49 | @property(nonatomic, assign) BOOL lastSyncIsDirectory; 50 | 51 | @end 52 | 53 | @interface NSManagedObject (Children) 54 | - (void)addChildrenObject:(PathMetadata *)aChild; 55 | - (void)removeChildrenObject:(PathMetadata *)aChild; 56 | @end -------------------------------------------------------------------------------- /Source/PathMetadata.m: -------------------------------------------------------------------------------- 1 | // 2 | // PathMetadata.m 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/7/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "PathMetadata.h" 10 | #import "PathController.h" 11 | #import "PathOperation.h" 12 | 13 | 14 | @interface PathController (PathMetadataPrivate) 15 | - (void)setPathMetadata:(PathMetadata *)aPathMetadata forNormalizedPath:(NSString *)aNormalizedPath; 16 | @end 17 | 18 | @implementation PathMetadata 19 | 20 | + (PathMetadata *)pathMetadataWithNormalizedName:(NSString *)aNormalizedName managedObjectContext:(NSManagedObjectContext *)aManagedObjectContext { 21 | PathMetadata *pathMetadata = [NSEntityDescription insertNewObjectForEntityForName:@"PathMetadata" inManagedObjectContext:aManagedObjectContext]; 22 | [pathMetadata setPrimitiveValue:aNormalizedName forKey:@"normalizedName"]; 23 | return pathMetadata; 24 | } 25 | 26 | #pragma mark - 27 | #pragma mark Dealloc 28 | 29 | - (void)didTurnIntoFault { 30 | [pathError release]; 31 | [normalizedPath release]; 32 | [super didTurnIntoFault]; 33 | } 34 | 35 | - (void)awakeFromFetch { 36 | [super awakeFromFetch]; 37 | [self.pathController setPathMetadata:self forNormalizedPath:self.normalizedPath]; 38 | } 39 | 40 | - (BOOL)isRoot { 41 | return self.parent == nil; 42 | } 43 | 44 | @dynamic normalizedName; 45 | 46 | - (NSString *)normalizedPath { 47 | if (!normalizedPath) { 48 | NSString *aPath = nil; 49 | if (self.parent) { 50 | aPath = [self.parent.normalizedPath stringByAppendingPathComponent:self.normalizedName]; 51 | } else { 52 | aPath = [@"/" stringByAppendingPathComponent:self.normalizedName]; 53 | } 54 | [normalizedPath release]; 55 | normalizedPath = [aPath retain]; 56 | } 57 | return normalizedPath; 58 | } 59 | 60 | - (PathController *)pathController { 61 | return [(PathControllerManagedObjectContext *)self.managedObjectContext pathController]; 62 | } 63 | 64 | @synthesize pathError; 65 | 66 | - (void)setPathError:(NSError *)anError { 67 | [pathError autorelease]; 68 | pathError = [anError retain]; 69 | } 70 | 71 | #pragma mark - 72 | #pragma mark Children 73 | 74 | @dynamic parent; 75 | @dynamic children; 76 | 77 | - (NSSet* )allDescendantsWithSelf { 78 | NSMutableSet *results = [NSMutableSet set]; 79 | for (PathMetadata *each in self.children) { 80 | [results unionSet:each.allDescendantsWithSelf]; 81 | } 82 | [results addObject:self]; 83 | return results; 84 | } 85 | 86 | #pragma mark - 87 | #pragma mark Last Sync Metadata 88 | 89 | - (PathState)pathState { 90 | [self willAccessValueForKey:@"pathState"]; 91 | BOOL result = pathState; 92 | [self didAccessValueForKey:@"pathState"]; 93 | return result; 94 | } 95 | 96 | - (void)setPathState:(PathState)newState { 97 | [self willChangeValueForKey:@"pathState"]; 98 | if (pathState != newState) { 99 | pathState = newState; 100 | } 101 | [self didChangeValueForKey:@"pathState"]; 102 | } 103 | 104 | @dynamic lastSyncName; 105 | @dynamic lastSyncDate; 106 | @dynamic lastSyncHash; 107 | @dynamic lastSyncIsDirectory; 108 | 109 | - (BOOL)lastSyncIsDirectory { 110 | [self willAccessValueForKey:@"lastSyncIsDirectory"]; 111 | BOOL result = lastSyncIsDirectory; 112 | [self didAccessValueForKey:@"lastSyncIsDirectory"]; 113 | return result; 114 | } 115 | 116 | - (void)setLastSyncIsDirectory:(BOOL)aBool { 117 | [self willChangeValueForKey:@"lastSyncIsDirectory"]; 118 | lastSyncIsDirectory = aBool; 119 | [self didChangeValueForKey:@"lastSyncIsDirectory"]; 120 | } 121 | 122 | @end 123 | 124 | @implementation PathController (PathMetadataPrivate) 125 | 126 | - (void)setPathMetadata:(PathMetadata *)aPathMetadata forNormalizedPath:(NSString *)aNormalizedPath { 127 | [normalizedPathsToPathMetadatas setObject:aPathMetadata forKey:aNormalizedPath]; 128 | } 129 | 130 | @end 131 | -------------------------------------------------------------------------------- /Source/PathMetadata.xcdatamodeld/.xccurrentversion: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | _XCCurrentVersionName 6 | PathMetadata.xcdatamodel 7 | 8 | 9 | -------------------------------------------------------------------------------- /Source/PathMetadata.xcdatamodeld/PathMetadata.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/Source/PathMetadata.xcdatamodeld/PathMetadata.xcdatamodel/elements -------------------------------------------------------------------------------- /Source/PathMetadata.xcdatamodeld/PathMetadata.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/Source/PathMetadata.xcdatamodeld/PathMetadata.xcdatamodel/layout -------------------------------------------------------------------------------- /Source/PathOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // SyncPathOperation.h 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/7/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "DropboxSDK.h" 10 | #import "PathMetadata.h" 11 | 12 | // 13 | // Base for all path sync operations. 14 | // 15 | 16 | @class FolderSyncPathOperation; 17 | 18 | @interface PathOperation : NSOperation { 19 | BOOL isExecuting; 20 | BOOL isFinished; 21 | BOOL updatedLastSyncHashOnFinish; 22 | BOOL createPathMetadataOnFinish; 23 | PathState successPathState; 24 | DBRestClient *client; 25 | NSString *localPath; 26 | DBMetadata *serverMetadata; 27 | NSUInteger retriesRemaining; 28 | FolderSyncPathOperation *folderSyncPathOperation; 29 | } 30 | 31 | + (PathOperation *)pathOperationWithPath:(NSString *)aLocalPath serverMetadata:(DBMetadata *)aServerMetadata; 32 | 33 | - (id)initWithPath:(NSString *)aLocalPath serverMetadata:(DBMetadata *)aServerMetadata; 34 | 35 | @property (readonly) BOOL isExecuting; 36 | @property (readonly) BOOL isFinished; 37 | @property (assign) BOOL createPathMetadataOnFinish;; 38 | @property (assign) PathState successPathState; 39 | @property (readonly) DBRestClient *client; 40 | @property (nonatomic, retain) DBMetadata *serverMetadata; 41 | @property (readonly) PathController *pathController; 42 | @property (readonly) PathControllerLogLevel logLevel; 43 | @property (nonatomic, retain) FolderSyncPathOperation *folderSyncPathOperation; 44 | 45 | - (void)log:(NSString *)aString level:(PathControllerLogLevel)level prettyFunction:(const char *)prettyFunction line:(NSUInteger)line; 46 | - (PathMetadata *)pathMetadata:(BOOL)createIfNeccessary; 47 | - (void)updatePathActivity:(PathActivity)pathActivity; 48 | - (void)deleteLocalPath; 49 | 50 | - (void)finish; 51 | - (void)retryWithError:(NSError *)error; 52 | - (void)retrySelector:(SEL)aSelector withError:(NSError *)error; 53 | - (void)finish:(NSError *)error; 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /Source/PutPathOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // PutPathOperation.h 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/10/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "PathOperation.h" 10 | 11 | // 12 | // Put local file to path on server. 13 | // 14 | 15 | @interface PutPathOperation : PathOperation { 16 | NSString *tempUploadPath; 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Source/PutPathOperation.m: -------------------------------------------------------------------------------- 1 | // 2 | // PutPathOperation.m 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/10/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import "PutPathOperation.h" 10 | #import "NSFileManager_Additions.h" 11 | #import "FolderSyncPathOperation.h" 12 | #import "PathController_Private.h" 13 | #import "PathController.h" 14 | #import "PathMetadata.h" 15 | 16 | 17 | @implementation PutPathOperation 18 | 19 | - (void)removeTempUploadPath { 20 | if (tempUploadPath) { 21 | [[NSFileManager defaultManager] removeItemAtPath:tempUploadPath error:NULL]; 22 | [tempUploadPath release]; 23 | tempUploadPath = nil; 24 | } 25 | } 26 | 27 | - (void)dealloc { 28 | [self removeTempUploadPath]; 29 | [super dealloc]; 30 | } 31 | 32 | - (void)main { 33 | NSString *serverPath = [self.pathController localPathToServer:localPath]; 34 | NSFileManager *fileManager = [NSFileManager defaultManager]; 35 | NSError *error; 36 | 37 | BOOL isDirectory; 38 | if ([fileManager fileExistsAtPath:localPath isDirectory:&isDirectory]) { 39 | if (isDirectory) { 40 | [self updatePathActivity:PutPathActivity]; 41 | [self.client createFolder:serverPath]; 42 | } else { 43 | tempUploadPath = [[fileManager tempDirectoryUnusedPath] retain]; 44 | if ([fileManager copyItemAtPath:localPath toPath:tempUploadPath error:&error]) { 45 | [self updatePathActivity:PutPathActivity]; 46 | [self.client uploadFile:[serverPath lastPathComponent] toPath:[serverPath stringByDeletingLastPathComponent] fromPath:tempUploadPath]; 47 | } else { 48 | [self finish:error]; 49 | } 50 | } 51 | } else { 52 | [self finish]; 53 | } 54 | } 55 | 56 | - (void)retryWithError:(NSError *)error { 57 | [self removeTempUploadPath]; 58 | [super retryWithError:error]; 59 | } 60 | 61 | #pragma mark - 62 | #pragma mark DBRestClientDelegate 63 | 64 | - (void)restClient:(DBRestClient*)aClient createdFolder:(DBMetadata *)aServerMetadata { 65 | self.serverMetadata = aServerMetadata; 66 | [self finish]; 67 | } 68 | 69 | - (void)restClient:(DBRestClient*)aClient createFolderFailedWithError:(NSError*)error { 70 | [self retryWithError:error]; 71 | } 72 | 73 | - (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath from:(NSString*)srcPath { 74 | PathMetadata *pathMetadata = [self pathMetadata:YES]; 75 | 76 | pathMetadata.pathState = SyncedPathState; 77 | [self.pathController enqueuePathChangedNotification:localPath changeType:StateChangedPathsKey]; 78 | pathMetadata.lastSyncIsDirectory = NO; 79 | pathMetadata.lastSyncName = [localPath lastPathComponent]; 80 | pathMetadata.lastSyncDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:srcPath error:NULL] fileModificationDate]; 81 | [pathMetadata.managedObjectContext save:NULL]; 82 | 83 | [self.client loadMetadata:[self.pathController localPathToServer:localPath]]; 84 | } 85 | 86 | - (void)restClient:(DBRestClient*)aClient uploadFileFailedWithError:(NSError*)error { 87 | [self retryWithError:error]; 88 | } 89 | 90 | #pragma mark - 91 | #pragma mark DBRestClientDelegate 92 | 93 | - (void)restClient:(DBRestClient*)aClient loadedMetadata:(DBMetadata*)aServerMetadata { 94 | NSFileManager *fileManager = [NSFileManager defaultManager]; 95 | PathMetadata *pathMetadata = [self pathMetadata:NO]; 96 | 97 | self.serverMetadata = aServerMetadata; 98 | 99 | if (pathMetadata != nil && !pathMetadata.isDeleted && [fileManager fileExistsAtPath:localPath]) { 100 | NSDate *lastSyncDate = pathMetadata.lastSyncDate; 101 | NSDate *currentDate = [[fileManager attributesOfItemAtPath:localPath error:NULL] fileModificationDate]; 102 | 103 | if ([lastSyncDate isEqualToDate:currentDate]) { 104 | [fileManager setAttributes:[NSDictionary dictionaryWithObject:serverMetadata.lastModifiedDate forKey:NSFileModificationDate] ofItemAtPath:localPath error:NULL]; 105 | [self.pathController enqueuePathChangedNotification:localPath changeType:ModifiedPathsKey]; 106 | } 107 | } 108 | 109 | [self finish]; 110 | } 111 | 112 | - (void)restClient:(DBRestClient*)aClient loadMetadataFailedWithError:(NSError*)error { 113 | [self finish:error]; 114 | } 115 | 116 | @end 117 | -------------------------------------------------------------------------------- /Tests/DropboxTestFolderFixture/1 はじめ.txt: -------------------------------------------------------------------------------- 1 | one 2 | -------------------------------------------------------------------------------- /Tests/DropboxTestFolderFixture/2 ū.txt: -------------------------------------------------------------------------------- 1 | two 2 | -------------------------------------------------------------------------------- /Tests/DropboxTestFolderFixture/3.txt: -------------------------------------------------------------------------------- 1 | three 2 | -------------------------------------------------------------------------------- /Tests/DropboxTestFolderFixture/4 ぜら/boo/hello.txt: -------------------------------------------------------------------------------- 1 | three 2 | -------------------------------------------------------------------------------- /Tests/DropboxTestFolderFixture/4 ぜら/test.pages: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/Tests/DropboxTestFolderFixture/4 ぜら/test.pages -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/GHUnitIOS: -------------------------------------------------------------------------------- 1 | Versions/Current/GHUnitIOS -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Headers: -------------------------------------------------------------------------------- 1 | Versions/Current/Headers -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Resources: -------------------------------------------------------------------------------- 1 | Versions/Current/Resources -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/GHUnitIOS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jessegrosjean/DropboxSync/716e30daef20aa85fb1246115c597f78c04911af/Tests/GHUnitIOS.framework/Versions/A/GHUnitIOS -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHAsyncTestCase.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHAsyncTestCase.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 4/8/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestCase.h" 31 | 32 | // Some default statuses to use; Or define and use your own 33 | enum { 34 | kGHUnitWaitStatusUnknown = 0, 35 | kGHUnitWaitStatusSuccess, 36 | kGHUnitWaitStatusFailure, 37 | kGHUnitWaitStatusCancelled 38 | }; 39 | 40 | /*! 41 | Asynchronous test case with wait and notify. 42 | 43 | If notify occurs before wait has started (if it was a synchronous call), this test 44 | case will still work. 45 | 46 | Be sure to call prepare before the asynchronous method (otherwise an exception will raise). 47 | 48 | @code 49 | - (void)testSuccess { 50 | [self prepare]; 51 | 52 | // Do asynchronous task here 53 | [self performSelector:@selector(_succeed) withObject:nil afterDelay:0.1]; 54 | 55 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.0]; 56 | } 57 | 58 | - (void)_succeed { 59 | // Notice the forSelector points to the test above. This is so that 60 | // stray notifies don't error or falsely succeed other tests. 61 | // To ignore the check, forSelector can be NULL. 62 | [self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testSuccess)]; 63 | } 64 | @endcode 65 | */ 66 | @interface GHAsyncTestCase : GHTestCase { 67 | 68 | NSInteger waitForStatus_; 69 | NSInteger notifiedStatus_; 70 | 71 | BOOL prepared_; // Whether prepared was called before waitForStatus:timeout: 72 | NSRecursiveLock *lock_; // Lock to synchronize on 73 | SEL waitSelector_; // The selector we are waiting on 74 | 75 | NSArray *_runLoopModes; 76 | } 77 | 78 | /*! 79 | Run loop modes to run while waiting; 80 | Defaults to NSDefaultRunLoopMode, NSRunLoopCommonModes, NSConnectionReplyMode 81 | */ 82 | @property (retain, nonatomic) NSArray *runLoopModes; 83 | 84 | /*! 85 | Prepare before calling the asynchronous method. 86 | */ 87 | - (void)prepare; 88 | 89 | /*! 90 | Prepare and specify the selector we will use in notify. 91 | 92 | @param selector 93 | */ 94 | - (void)prepare:(SEL)selector; 95 | 96 | /*! 97 | Wait for notification of status or timeout. 98 | 99 | Be sure to prepare before calling your asynchronous method. 100 | For example, 101 | 102 | @code 103 | - (void)testFoo { 104 | [self prepare]; 105 | // Do asynchronous task here 106 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.0]; 107 | } 108 | @endcode 109 | 110 | @param status kGHUnitWaitStatusSuccess, kGHUnitWaitStatusFailure or custom status 111 | @param timeout Timeout in seconds 112 | */ 113 | - (void)waitForStatus:(NSInteger)status timeout:(NSTimeInterval)timeout; 114 | 115 | // Deprecated 116 | - (void)waitFor:(NSInteger)status timeout:(NSTimeInterval)timeout; 117 | 118 | /*! 119 | Wait for timeout to occur. 120 | Fails if we did _NOT_ timeout. 121 | @param timeout 122 | */ 123 | - (void)waitForTimeout:(NSTimeInterval)timeout; 124 | 125 | /*! 126 | Notify waiting of status for test selector. 127 | @param status Status, for example, kGHUnitWaitStatusSuccess 128 | @param selector If not NULL, then will verify this selector is where we are waiting. 129 | This prevents stray asynchronous callbacks to fail a later test 130 | */ 131 | - (void)notify:(NSInteger)status forSelector:(SEL)selector; 132 | 133 | /*! 134 | Notify waiting of status for any selector. 135 | @param status Status, for example, kGHUnitWaitStatusSuccess 136 | */ 137 | - (void)notify:(NSInteger)status; 138 | 139 | @end 140 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHTest+JUnitXML.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTest+JUnitXML.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 6/4/10. 6 | // Copyright 2010. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTest.h" 31 | 32 | @interface GHTest (JUnitXML) 33 | 34 | /*! 35 | Return test results in JUnit XML format for external parsing use 36 | (such as a Continuous Integration system like Hudson) 37 | */ 38 | - (NSString *)JUnitXML; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHTestCase.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestCase.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 1/21/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | // 31 | // Portions of this file fall under the following license, marked with: 32 | // GTM_BEGIN : GTM_END 33 | // 34 | // Copyright 2008 Google Inc. 35 | // 36 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 37 | // use this file except in compliance with the License. You may obtain a copy 38 | // of the License at 39 | // 40 | // http://www.apache.org/licenses/LICENSE-2.0 41 | // 42 | // Unless required by applicable law or agreed to in writing, software 43 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 44 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 45 | // License for the specific language governing permissions and limitations under 46 | // the License. 47 | // 48 | 49 | #import "GHTestMacros.h" 50 | #import "GHTest.h" 51 | 52 | // Log to your test case logger. 53 | // For example, GHTestLog(@"Some debug info, %@", obj) 54 | #define GHTestLog(...) [self log:[NSString stringWithFormat:__VA_ARGS__, nil]] 55 | 56 | /*! 57 | The base class for a test case. 58 | 59 | @code 60 | @interface MyTest : GHTestCase {} 61 | @end 62 | 63 | @implementation MyTest 64 | 65 | // Run before each test method 66 | - (void)setUp { } 67 | 68 | // Run after each test method 69 | - (void)tearDown { } 70 | 71 | // Run before the tests are run for this class 72 | - (void)setUpClass { } 73 | 74 | // Run before the tests are run for this class 75 | - (void)tearDownClass { } 76 | 77 | // Tests are prefixed by 'test' and contain no arguments and no return value 78 | - (void)testA { 79 | GHTestLog(@"Log with a test with the GHTestLog(...) for test specific logging."); 80 | } 81 | 82 | // Another test; Tests are run in lexical order 83 | - (void)testB { } 84 | 85 | // Override any exceptions; By default exceptions are raised, causing a test failure 86 | - (void)failWithException:(NSException *)exception { } 87 | 88 | @end 89 | @endcode 90 | 91 | */ 92 | @interface GHTestCase : NSObject { 93 | id logWriter_; // weak 94 | 95 | SEL currentSelector_; 96 | } 97 | 98 | //! The current test selector 99 | @property (assign, nonatomic) SEL currentSelector; 100 | @property (assign, nonatomic) id logWriter; 101 | 102 | // GTM_BEGIN 103 | //! Run before each test method 104 | - (void)setUp; 105 | 106 | //! Run after each test method 107 | - (void)tearDown; 108 | 109 | /*! 110 | By default exceptions are raised, causing a test failure 111 | @brief Override any exceptions 112 | @param exception Exception that was raised by test 113 | */ 114 | - (void)failWithException:(NSException*)exception; 115 | // GTM_END 116 | 117 | //! Run before the tests (once per test case) 118 | - (void)setUpClass; 119 | 120 | //! Run after the tests (once per test case) 121 | - (void)tearDownClass; 122 | 123 | /*! 124 | Whether to run the tests on a separate thread. Override this method in your 125 | test case to override the default. 126 | Default is NO, tests are run on a separate thread by default. 127 | @result If YES runs on the main thread 128 | */ 129 | - (BOOL)shouldRunOnMainThread; 130 | 131 | //! Any special handling of exceptions after they are thrown; By default logs stack trace to standard out. 132 | - (void)handleException:(NSException *)exception; 133 | 134 | /*! 135 | Log a message, which notifies the log delegate. 136 | This is not meant to be used directly, see GHTestLog(...) macro. 137 | @param message 138 | */ 139 | - (void)log:(NSString *)message; 140 | 141 | @end 142 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHTestGroup+JUnitXML.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestGroup+JUnitXML.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 6/4/10. 6 | // Copyright 2010. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestGroup.h" 31 | 32 | @interface GHTestGroup (JUnitXML) 33 | 34 | - (NSString *)JUnitXML; 35 | 36 | - (BOOL)writeJUnitXMLAtPath:(NSString *)documentsPath error:(NSError **)error; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHTestGroup.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestGroup.h 3 | // 4 | // Created by Gabriel Handford on 1/16/09. 5 | // Copyright 2009. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "GHTest.h" 30 | #import "GHTestCase.h" 31 | 32 | /*! 33 | @brief Interface for a group of tests. 34 | 35 | This group conforms to the GHTest protocol as well (see Composite pattern). 36 | */ 37 | @protocol GHTestGroup 38 | - (NSString *)name; 39 | - (id)parent; 40 | - (NSArray *)children; 41 | @end 42 | 43 | /*! 44 | @brief A collection of tests (or test groups). 45 | 46 | A test group is a collection of id, that may represent a set of test case methods. 47 | 48 | For example, if you had the following GHTestCase. 49 | 50 | @code 51 | @interface FooTest : GHTestCase {} 52 | - (void)testFoo; 53 | - (void)testBar; 54 | @end 55 | @endcode 56 | 57 | The GHTestGroup would consist of and array of GHTest, [FooTest#testFoo and FooTest#testBar], 58 | each test being a target and selector pair. 59 | 60 | A test group may also consist of a group of groups (since GHTestGroup conforms to GHTest), 61 | and this might represent a GHTestSuite. 62 | */ 63 | @interface GHTestGroup : NSObject { 64 | 65 | NSObject *delegate_; // weak 66 | id parent_; // weak 67 | 68 | NSMutableArray */*of id*/children_; 69 | 70 | NSString *name_; // The name of the test group (usually the class name of the test case 71 | NSTimeInterval interval_; // Total time of child tests 72 | GHTestStatus status_; // Current status of the group (current status of running or completed child tests) 73 | GHTestStats stats_; // Current stats for the group (aggregate of child test stats) 74 | 75 | BOOL didSetUpClass_; 76 | 77 | GHTestOptions options_; 78 | 79 | // Set if test is created from initWithTestCase:delegate: 80 | // Allows use to perform setUpClass and tearDownClass (once per test case run) 81 | id testCase_; 82 | 83 | NSException *exception_; // If exception happens in group setUpClass/tearDownClass 84 | } 85 | 86 | @property (readonly, nonatomic) NSArray */*of id*/children; 87 | @property (assign, nonatomic) id parent; 88 | @property (readonly, nonatomic) id testCase; 89 | @property (assign, nonatomic) GHTestOptions options; 90 | 91 | /*! 92 | Create an empty test group. 93 | @param name The name of the test group 94 | @param delegate Delegate, notifies of test start and end 95 | @result New test group 96 | */ 97 | - (id)initWithName:(NSString *)name delegate:(id)delegate; 98 | 99 | /*! 100 | Create test group from a test case. 101 | @param testCase Test case, could be a subclass of SenTestCase or GHTestCase 102 | @param delegate Delegate, notifies of test start and end 103 | @result New test group 104 | */ 105 | - (id)initWithTestCase:(id)testCase delegate:(id)delegate; 106 | 107 | /*! 108 | Create test group from a single test. 109 | @param testCase 110 | @param selector Test to run 111 | @param delegate 112 | */ 113 | - (id)initWithTestCase:(id)testCase selector:(SEL)selector delegate:(id)delegate; 114 | 115 | /*! 116 | Create test group from a test case. 117 | @param testCase Test case, could be a subclass of SenTestCase or GHTestCase 118 | @param delegate Delegate, notifies of test start and end 119 | @result New test group 120 | */ 121 | + (GHTestGroup *)testGroupFromTestCase:(id)testCase delegate:(id)delegate; 122 | 123 | /*! 124 | Add a test case (or test group) to this test group. 125 | @param testCase Test case, could be a subclass of SenTestCase or GHTestCase 126 | */ 127 | - (void)addTestCase:(id)testCase; 128 | 129 | - (void)addTestGroup:(GHTestGroup *)testGroup; 130 | 131 | - (void)addTests:(NSArray */*of id*/)tests; 132 | 133 | - (void)addTest:(id)test; 134 | 135 | - (BOOL)shouldRunOnMainThread; 136 | 137 | /*! 138 | Get list of failed tests. 139 | @result Failed tests 140 | */ 141 | - (NSArray */*of id*/)failedTests; 142 | 143 | /*! 144 | Run in operation queue. 145 | Tests from the group are added and will block until they have completed. 146 | @param operationQueue If nil, then runs as is 147 | @param options Options 148 | */ 149 | - (void)runInOperationQueue:(NSOperationQueue *)operationQueue options:(GHTestOptions)options; 150 | 151 | @end 152 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHTestOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestOperation.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 6/4/10. 6 | // Copyright 2010. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTest.h" 31 | 32 | /*! 33 | Test for running in the context of an NSOperationQueue. 34 | */ 35 | @interface GHTestOperation : NSOperation { 36 | id test_; 37 | GHTestOptions options_; 38 | } 39 | 40 | - (id)initWithTest:(id)test options:(GHTestOptions)options; 41 | 42 | @end -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHTestRunner.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestRunner.h 3 | // 4 | // Created by Gabriel Handford on 1/16/09. 5 | // Copyright 2008 Gabriel Handford 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | // 30 | // Portions of this file fall under the following license, marked with: 31 | // GTM_BEGIN : GTM_END 32 | // 33 | // Copyright 2008 Google Inc. 34 | // 35 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 36 | // use this file except in compliance with the License. You may obtain a copy 37 | // of the License at 38 | // 39 | // http://www.apache.org/licenses/LICENSE-2.0 40 | // 41 | // Unless required by applicable law or agreed to in writing, software 42 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 43 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 44 | // License for the specific language governing permissions and limitations under 45 | // the License. 46 | // 47 | 48 | #import "GHTestGroup.h" 49 | #import "GHTestSuite.h" 50 | 51 | @class GHTestRunner; 52 | 53 | // Delegates can be guaranteed to be notified on the main thread (using #delegateOnMainThread) 54 | @protocol GHTestRunnerDelegate 55 | @optional 56 | - (void)testRunnerDidStart:(GHTestRunner *)runner; 57 | - (void)testRunner:(GHTestRunner *)runner didStartTest:(id)test; // Test started 58 | - (void)testRunner:(GHTestRunner *)runner didUpdateTest:(id)test; // Test changed 59 | - (void)testRunner:(GHTestRunner *)runner didEndTest:(id)test; // Test finished 60 | - (void)testRunnerDidCancel:(GHTestRunner *)runner; 61 | - (void)testRunnerDidEnd:(GHTestRunner *)runner; 62 | 63 | - (void)testRunner:(GHTestRunner *)runner didLog:(NSString *)message; // Runner logged message 64 | - (void)testRunner:(GHTestRunner *)runner test:(id)test didLog:(NSString *)message; // Test logged message 65 | @end 66 | 67 | /*! 68 | Runs the tests. 69 | Tests are run a separate thread though delegates are called on the 70 | main thread by default (see #delegateOnMainThread). 71 | */ 72 | @interface GHTestRunner : NSObject { 73 | 74 | id test_; // The test to run; Could be a GHTestGroup (suite), GHTestGroup (test case), or GHTest (target/selector) 75 | 76 | NSObject *delegate_; // weak 77 | 78 | GHTestOptions options_; 79 | 80 | BOOL running_; 81 | BOOL cancelling_; 82 | 83 | NSTimeInterval startInterval_; 84 | 85 | NSOperationQueue *operationQueue_; //! If running a suite in operation queue 86 | } 87 | 88 | @property (retain) id test; 89 | @property (assign) NSObject *delegate; 90 | @property (assign) GHTestOptions options; 91 | @property (readonly) GHTestStats stats; 92 | @property (readonly, getter=isRunning) BOOL running; 93 | @property (readonly, getter=isCancelling) BOOL cancelling; 94 | @property (readonly) NSTimeInterval interval; 95 | @property (retain, nonatomic) NSOperationQueue *operationQueue; 96 | 97 | 98 | /*! 99 | Create runner for test. 100 | @param test 101 | */ 102 | - (id)initWithTest:(id)test; 103 | 104 | /*! 105 | Create runner for all tests. 106 | @see GHTesting#loadAllTestCases. 107 | @result Runner 108 | */ 109 | + (GHTestRunner *)runnerForAllTests; 110 | 111 | /*! 112 | Create runner for test suite. 113 | @param suite 114 | @result Runner 115 | */ 116 | + (GHTestRunner *)runnerForSuite:(GHTestSuite *)suite; 117 | 118 | /*! 119 | Create runner for class and method. 120 | @param testClassName 121 | @param methodName 122 | @result Runner 123 | */ 124 | + (GHTestRunner *)runnerForTestClassName:(NSString *)testClassName methodName:(NSString *)methodName; 125 | 126 | /*! 127 | Get the runner from the environment. 128 | If the TEST env is set, then we will only run that test case or test method. 129 | */ 130 | + (GHTestRunner *)runnerFromEnv; 131 | 132 | /*! 133 | Run the test runner. Usually called from the test main. 134 | Reads the TEST environment variable and filters on that; or all tests are run. 135 | @result 0 is success, otherwise the failure count 136 | */ 137 | + (int)run; 138 | 139 | - (void)runInBackground; 140 | 141 | /*! 142 | Start the test runner with the default test. 143 | @result 0 is success, otherwise the failure count 144 | */ 145 | - (int)runTests; 146 | 147 | - (void)cancel; 148 | 149 | - (void)setInParallel:(BOOL)inParallel; 150 | - (BOOL)isInParallel; 151 | 152 | /*! 153 | Write message to console. 154 | */ 155 | - (void)log:(NSString *)message; 156 | 157 | @end 158 | 159 | 160 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHTestSuite.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestSuite.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 1/25/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestGroup.h" 31 | 32 | /*! 33 | If set, will run it as a "test filter" like the env variable TEST. 34 | */ 35 | extern NSString *GHUnitTest; 36 | 37 | 38 | /*! 39 | Test suite is an alias for test group. 40 | 41 | A test case is an instance of a test case class with test methods. 42 | A test is a id which represents a target and a selector. 43 | A test group is a collection of tests; A collection of id (GHTest or GHTestGroup). 44 | 45 | For example, if you have 2 test cases, GHTestCase1 (with some test methods) and GHTestCase2 (with some test methods), 46 | your test suite might look like: 47 | 48 | "Tests" (GHTestSuite) 49 | GHTestGroup (collection of tests from GHTestCase1) 50 | - (void)testA1 (GHTest with target GHTestCase1 + testA1) 51 | - (void)testA2 (GHTest with target GHTestCase1 + testA2) 52 | GHTestGroup (collection of tests from GHTestCase2) 53 | - (void)testB1; (GHTest with target GHTestCase2 + testB1) 54 | - (void)testB2; (GHTest with target GHTestCase2 + testB2) 55 | 56 | */ 57 | @interface GHTestSuite : GHTestGroup { } 58 | 59 | /*! 60 | Create test suite with test cases. 61 | @param name Label to give the suite 62 | @param testCases Array of init'ed test case classes 63 | @param delegate 64 | */ 65 | - (id)initWithName:(NSString *)name testCases:(NSArray *)testCases delegate:(id)delegate; 66 | 67 | /*! 68 | Creates a suite of all tests. 69 | Will load all classes that subclass from GHTestCase, SenTestCase or GTMTestCase (or register test case class). 70 | @result Suite 71 | */ 72 | + (GHTestSuite *)allTests; 73 | 74 | /*! 75 | Create suite of tests with filter. 76 | This is useful for running a single test or all tests in a single test case. 77 | 78 | For example, 79 | 'GHSlowTest' -- Runs all test method in GHSlowTest 80 | 'GHSlowTest/testSlowA -- Only runs the test method testSlowA in GHSlowTest 81 | 82 | @param testFilter Test filter 83 | @result Suite 84 | */ 85 | + (GHTestSuite *)suiteWithTestFilter:(NSString *)testFilter; 86 | 87 | /*! 88 | Create suite of tests that start with prefix. 89 | @param prefix If test case class starts with the prefix; If nil or empty string, returns all tests 90 | @param options Compare options 91 | */ 92 | + (GHTestSuite *)suiteWithPrefix:(NSString *)prefix options:(NSStringCompareOptions)options; 93 | 94 | /*! 95 | Suite for a single test/method. 96 | @param testCaseClass 97 | @param method 98 | @result Suite 99 | */ 100 | + (GHTestSuite *)suiteWithTestCaseClass:(Class)testCaseClass method:(SEL)method; 101 | 102 | /*! 103 | Return test suite based on environment (TEST=TestFoo/foo) 104 | @result Suite 105 | */ 106 | + (GHTestSuite *)suiteFromEnv; 107 | 108 | @end 109 | 110 | @interface GHTestSuite (JUnitXML) 111 | 112 | - (BOOL)writeJUnitXML:(NSError **)error; 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHTesting.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTesting.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 1/30/09. 6 | // Copyright 2008 Gabriel Handford 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | // 31 | // Portions of this file fall under the following license, marked with: 32 | // GTM_BEGIN : GTM_END 33 | // 34 | // Copyright 2008 Google Inc. 35 | // 36 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 37 | // use this file except in compliance with the License. You may obtain a copy 38 | // of the License at 39 | // 40 | // http://www.apache.org/licenses/LICENSE-2.0 41 | // 42 | // Unless required by applicable law or agreed to in writing, software 43 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 44 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 45 | // License for the specific language governing permissions and limitations under 46 | // the License. 47 | // 48 | 49 | extern NSString *GHUStackTraceFromException(NSException *e); 50 | 51 | // GTM_BEGIN 52 | BOOL isTestFixtureOfClass(Class aClass, Class testCaseClass); 53 | // GTM_END 54 | 55 | /*! 56 | Utility test for loading and running tests. 57 | @note Much of this is borrowed from GTM/UnitTesting. 58 | */ 59 | @interface GHTesting : NSObject { 60 | 61 | NSMutableArray/* of NSString*/ *testCaseClassNames_; 62 | 63 | } 64 | 65 | /*! 66 | The shared testing instance. 67 | */ 68 | + (GHTesting *)sharedInstance; 69 | 70 | /*! 71 | Load all test classes that we can "see". 72 | @result Array of initialized (and autoreleased) test case classes in an autoreleased array. 73 | */ 74 | - (NSArray *)loadAllTestCases; 75 | 76 | /*! 77 | Load tests from target. 78 | @result Array of id 79 | */ 80 | - (NSArray *)loadTestsFromTarget:(id)target; 81 | 82 | /*! 83 | See if class is of a registered test case class. 84 | */ 85 | - (BOOL)isTestCaseClass:(Class)aClass; 86 | 87 | /*! 88 | Register test case class. 89 | @param aClass 90 | */ 91 | - (void)registerClass:(Class)aClass; 92 | 93 | /*! 94 | Register test case class by name. 95 | @param className Class name (via NSStringFromClass(aClass) 96 | */ 97 | - (void)registerClassName:(NSString *)className; 98 | 99 | /*! 100 | Format test exception. 101 | @param exception 102 | @result Description 103 | */ 104 | + (NSString *)descriptionForException:(NSException *)exception; 105 | 106 | /*! 107 | Filename for cause of test exception. 108 | @param test 109 | @result Filename 110 | */ 111 | + (NSString *)exceptionFilenameForTest:(id)test; 112 | 113 | /*! 114 | Line number for cause of test exception. 115 | @param test 116 | @result Line number 117 | */ 118 | + (NSInteger)exceptionLineNumberForTest:(id)test; 119 | 120 | /*! 121 | Run test. 122 | @param target 123 | @param selector 124 | @param exception Exception, if set, is retained and should be released by the caller. 125 | @param interval Time to run the test 126 | @param reraiseExceptions If YES, will re-raise exceptions 127 | */ 128 | + (BOOL)runTestWithTarget:(id)target selector:(SEL)selector exception:(NSException **)exception 129 | interval:(NSTimeInterval *)interval reraiseExceptions:(BOOL)reraiseExceptions; 130 | 131 | /*! 132 | Same as normal runTest without catching exceptions. 133 | */ 134 | + (BOOL)runTestOrRaiseWithTarget:(id)target selector:(SEL)selector exception:(NSException **)exception interval:(NSTimeInterval *)interval; 135 | 136 | @end 137 | 138 | @protocol GHSenTestCase 139 | - (void)raiseAfterFailure; 140 | @end 141 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHUnit.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnit.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 1/19/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestCase.h" 31 | #import "GHAsyncTestCase.h" 32 | #import "GHTestSuite.h" 33 | #import "GHTestMacros.h" 34 | #import "GHTestRunner.h" 35 | 36 | #import "GHTest.h" 37 | #import "GHTesting.h" 38 | #import "GHTestOperation.h" 39 | #import "GHTestGroup.h" 40 | #import "GHTest+JUnitXML.h" 41 | #import "GHTestGroup+JUnitXML.h" 42 | #import "NSException+GHTestFailureExceptions.h" 43 | #import "NSValue+GHValueFormatter.h" 44 | 45 | #ifdef DEBUG 46 | #define GHUDebug(fmt, ...) do { \ 47 | fputs([[[NSString stringWithFormat:fmt, ##__VA_ARGS__] stringByAppendingString:@"\n"] UTF8String], stdout); \ 48 | } while(0) 49 | #else 50 | #define GHUDebug(fmt, ...) do {} while(0) 51 | #endif -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHUnitIOS.h: -------------------------------------------------------------------------------- 1 | 2 | #import "GHUnit.h" 3 | #import "GHUnitIPhoneAppDelegate.h" -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHUnitIPhoneAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnitIPhoneAppDelegate.h 3 | // GHUnitIPhone 4 | // 5 | // Created by Gabriel Handford on 1/25/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | @interface GHUnitIPhoneAppDelegate : NSObject { 33 | UIWindow *window_; 34 | 35 | UINavigationController *navigationController_; 36 | } 37 | 38 | @end 39 | 40 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHUnitIPhoneTableViewDataSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnitIPhoneTableViewDataSource.h 3 | // GHUnitIPhone 4 | // 5 | // Created by Gabriel Handford on 5/5/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestViewModel.h" 31 | 32 | @interface GHUnitIPhoneTableViewDataSource : GHTestViewModel { 33 | 34 | } 35 | 36 | - (GHTestNode *)nodeForIndexPath:(NSIndexPath *)indexPath; 37 | 38 | - (void)setSelectedForAllNodes:(BOOL)selected; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHUnitIPhoneTestViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnitIPhoneTestViewController.h 3 | // GHUnitIPhone 4 | // 5 | // Created by Gabriel Handford on 2/20/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestViewModel.h" 31 | 32 | @interface GHUnitIPhoneTestViewController : UIViewController { 33 | UITextView *textView_; 34 | 35 | GHTestNode *testNode_; 36 | 37 | GHTestRunner *runner_; 38 | } 39 | 40 | - (void)setTest:(id)test; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHUnitIPhoneView.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnitIPhoneView.h 3 | // GHUnitIPhone 4 | // 5 | // Created by Gabriel Handford on 4/12/10. 6 | // Copyright 2010. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | 31 | @interface GHUnitIPhoneView : UIView { 32 | UISearchBar *searchBar_; 33 | 34 | UITableView *tableView_; 35 | 36 | //! Status label at bottom of the view 37 | UILabel *statusLabel_; 38 | 39 | UISegmentedControl *filterControl_; 40 | 41 | UIToolbar *runToolbar_; 42 | 43 | UIView *footerView_; 44 | } 45 | 46 | @property (readonly, nonatomic) UILabel *statusLabel; 47 | @property (readonly, nonatomic) UISegmentedControl *filterControl; 48 | @property (readonly, nonatomic) UISearchBar *searchBar; 49 | @property (readonly, nonatomic) UITableView *tableView; 50 | 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/GHUnitIPhoneViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnitIPhoneViewController.h 3 | // GHUnitIPhone 4 | // 5 | // Created by Gabriel Handford on 1/25/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHUnitIPhoneView.h" 31 | 32 | #import "GHUnitIPhoneTableViewDataSource.h" 33 | #import "GHUnitIPhoneTestViewController.h" 34 | 35 | @interface GHUnitIPhoneViewController : UIViewController { 36 | 37 | GHUnitIPhoneView *view_; 38 | 39 | //! Data source for table view 40 | GHUnitIPhoneTableViewDataSource *dataSource_; 41 | GHTestSuite *suite_; 42 | 43 | UIBarButtonItem *runButton_; 44 | 45 | //! If set then we will no longer auto scroll as tests are run 46 | BOOL userDidDrag_; 47 | 48 | } 49 | 50 | @property (retain, nonatomic) GHTestSuite *suite; 51 | 52 | - (void)reloadTest:(id)test; 53 | 54 | - (void)scrollToTest:(id)test; 55 | - (void)scrollToBottom; 56 | 57 | - (void)setStatusText:(NSString *)message; 58 | 59 | - (void)runTests; 60 | 61 | - (void)cancel; 62 | 63 | - (void)reload; 64 | 65 | - (void)loadDefaults; 66 | - (void)saveDefaults; 67 | 68 | - (GHUnitIPhoneTableViewDataSource *)dataSource; 69 | 70 | @end 71 | 72 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/NSException+GHTestFailureExceptions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSException+GHTestFailureExceptions.h 3 | // 4 | // Created by Johannes Rudolph on 23.09.09. 5 | // Copyright 2009. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | // 30 | // Portions of this file fall under the following license, marked with: 31 | // GTM_BEGIN : GTM_END 32 | // 33 | // Copyright 2008 Google Inc. 34 | // 35 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 36 | // use this file except in compliance with the License. You may obtain a copy 37 | // of the License at 38 | // 39 | // http://www.apache.org/licenses/LICENSE-2.0 40 | // 41 | // Unless required by applicable law or agreed to in writing, software 42 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 43 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 44 | // License for the specific language governing permissions and limitations under 45 | // the License. 46 | // 47 | 48 | extern NSString *const GHTestFilenameKey; 49 | extern NSString *const GHTestLineNumberKey; 50 | extern NSString *const GHTestFailureException; 51 | 52 | 53 | // GTM_BEGIN 54 | 55 | #import 56 | 57 | @interface NSException (GHUTestFailureExceptions) 58 | + (NSException *)ghu_failureInFile:(NSString *)filename 59 | atLine:(int)lineNumber 60 | withDescription:(NSString *)formatString, ...; 61 | + (NSException *)ghu_failureInCondition:(NSString *)condition 62 | isTrue:(BOOL)isTrue 63 | inFile:(NSString *)filename 64 | atLine:(int)lineNumber 65 | withDescription:(NSString *)formatString, ...; 66 | + (NSException *)ghu_failureInEqualityBetweenObject:(id)left 67 | andObject:(id)right 68 | inFile:(NSString *)filename 69 | atLine:(int)lineNumber 70 | withDescription:(NSString *)formatString, ...; 71 | + (NSException *)ghu_failureInEqualityBetweenValue:(NSValue *)left 72 | andValue:(NSValue *)right 73 | withAccuracy:(NSValue *)accuracy 74 | inFile:(NSString *)filename 75 | atLine:(int) ineNumber 76 | withDescription:(NSString *)formatString, ...; 77 | + (NSException *)ghu_failureInRaise:(NSString *)expression 78 | inFile:(NSString *)filename 79 | atLine:(int)lineNumber 80 | withDescription:(NSString *)formatString, ...; 81 | + (NSException *)ghu_failureInRaise:(NSString *)expression 82 | exception:(NSException *)exception 83 | inFile:(NSString *)filename 84 | atLine:(int)lineNumber 85 | withDescription:(NSString *)formatString, ...; 86 | @end 87 | 88 | // GTM_END -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Headers/NSValue+GHValueFormatter.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSValue+GHValueFormatter.h 3 | // 4 | // Created by Johannes Rudolph on 23.9.2009. 5 | // Copyright 2009. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | // 30 | // Portions of this file fall under the following license, marked with 31 | // SENTE_BEGIN - SENTE_END 32 | // 33 | // Copyright (c) 1997-2005, Sen:te (Sente SA). All rights reserved. 34 | // 35 | // Use of this source code is governed by the following license: 36 | // 37 | // Redistribution and use in source and binary forms, with or without modification, 38 | // are permitted provided that the following conditions are met: 39 | // 40 | // (1) Redistributions of source code must retain the above copyright notice, 41 | // this list of conditions and the following disclaimer. 42 | // 43 | // (2) Redistributions in binary form must reproduce the above copyright notice, 44 | // this list of conditions and the following disclaimer in the documentation 45 | // and/or other materials provided with the distribution. 46 | // 47 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 48 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 49 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 50 | // IN NO EVENT SHALL Sente SA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 51 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 52 | // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 54 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 55 | // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 | // 57 | // Note: this license is equivalent to the FreeBSD license. 58 | // 59 | // This notice may not be removed from this file. 60 | 61 | #import 62 | 63 | // SENTE_BEGIN 64 | @interface NSValue (GHValueFormatter) 65 | - (NSString *)ghu_contentDescription; 66 | @end 67 | // SENTE_END 68 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/A/Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleIdentifier 8 | me.rel.ghunit 9 | CFBundleInfoDictionaryVersion 10 | 6.0 11 | CFBundlePackageType 12 | FMWK 13 | CFBundleSignature 14 | ???? 15 | CFBundleVersion 16 | $(GHUNIT_VERSION) 17 | 18 | 19 | -------------------------------------------------------------------------------- /Tests/GHUnitIOS.framework/Versions/Current: -------------------------------------------------------------------------------- 1 | A -------------------------------------------------------------------------------- /Tests/GHUnitIPhoneTestMain.m: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnitIPhoneTestMain.m 3 | // GHUnitIPhone 4 | // 5 | // Created by Gabriel Handford on 1/25/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import 31 | 32 | #import 33 | 34 | // Default exception handler 35 | void exceptionHandler(NSException *exception) { 36 | NSLog(@"%@\n%@", [exception reason], GHUStackTraceFromException(exception)); 37 | } 38 | 39 | int main(int argc, char *argv[]) { 40 | 41 | /*! 42 | For debugging: 43 | Go into the "Get Info" contextual menu of your (test) executable (inside the "Executables" group in the left panel of XCode). 44 | Then go in the "Arguments" tab. You can add the following environment variables: 45 | 46 | Default: Set to: 47 | NSDebugEnabled NO "YES" 48 | NSZombieEnabled NO "YES" 49 | NSDeallocateZombies NO "YES" 50 | NSHangOnUncaughtException NO "YES" 51 | 52 | NSEnableAutoreleasePool YES "NO" 53 | NSAutoreleaseFreedObjectCheckEnabled NO "YES" 54 | NSAutoreleaseHighWaterMark 0 non-negative integer 55 | NSAutoreleaseHighWaterResolution 0 non-negative integer 56 | 57 | For info on these varaiables see NSDebug.h; http://theshadow.uw.hu/iPhoneSDKdoc/Foundation.framework/NSDebug.h.html 58 | 59 | For malloc debugging see: http://developer.apple.com/mac/library/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html 60 | */ 61 | 62 | NSSetUncaughtExceptionHandler(&exceptionHandler); 63 | 64 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 65 | 66 | // Register any special test case classes 67 | //[[GHTesting sharedInstance] registerClassName:@"GHSpecialTestCase"]; 68 | 69 | int retVal = 0; 70 | // If GHUNIT_CLI is set we are using the command line interface and run the tests 71 | // Otherwise load the GUI app 72 | if (getenv("GHUNIT_CLI")) { 73 | retVal = [GHTestRunner run]; 74 | } else { 75 | retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIPhoneAppDelegate"); 76 | } 77 | [pool release]; 78 | return retVal; 79 | } 80 | -------------------------------------------------------------------------------- /Tests/PathControllerTests.h: -------------------------------------------------------------------------------- 1 | // 2 | // PathControllerTests.h 3 | // DropboxSync 4 | // 5 | // Created by Jesse Grosjean on 8/15/10. 6 | // Copyright 2010 Hog Bay Software. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "DropboxSDK.h" 11 | #import "PathControllerDelegate.h" 12 | 13 | // Application keys 14 | #define CONSUMERKEY @"" 15 | #define CONSUMERSECRET @"" 16 | 17 | // Dropbox Account 18 | #define DROPBOXTESTACCOUNT @"" 19 | #define DROPBOXTESTACCOUNTPASSWORD @"" 20 | 21 | // Test folder fixture path (copy from PROJECT/Source/Tests/DropboxTestFolderFixture) and put in your dropbox folder. 22 | #define TEST_FOLDER_FIXTURE_DROPBOX_PATH @"/Testing/DropboxTestFolderFixture" 23 | 24 | @class PathController; 25 | 26 | @interface PathControllerTests : GHAsyncTestCase { 27 | DBRestClient *client; 28 | PathController *pathController; 29 | NSFileManager *fileManager; 30 | BOOL deleteFailMeansSuccess; 31 | } 32 | 33 | @end -------------------------------------------------------------------------------- /Tests/Tests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.hogbaysoftware.${PRODUCT_NAME:identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | APPL 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | 1.0 19 | 20 | 21 | --------------------------------------------------------------------------------