From 38192c6c93c05ef22da30f49ef4b315dbe63b58b Mon Sep 17 00:00:00 2001 From: Damien Rambout Date: Sun, 14 Sep 2014 13:13:42 +0200 Subject: [PATCH 1/6] Update project settings for Xcode 6 --- OAuth2Client.xcodeproj/project.pbxproj | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/OAuth2Client.xcodeproj/project.pbxproj b/OAuth2Client.xcodeproj/project.pbxproj index 9b1d5d82..0fdf9773 100644 --- a/OAuth2Client.xcodeproj/project.pbxproj +++ b/OAuth2Client.xcodeproj/project.pbxproj @@ -53,7 +53,6 @@ 942FFD7E12315EFF00E6C65E /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94E5AC92122C097B00C7021A /* Security.framework */; }; 945A500D123F7BAE00A6F2EB /* NXOAuth2ClientDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 824D5A6D123F68A8001177D5 /* NXOAuth2ClientDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 94B6CE7219C1D3E400AA859B /* NXOAuth2PostBodyStreamSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 94B6CE7119C1D3E400AA859B /* NXOAuth2PostBodyStreamSpec.m */; }; - 94B6CE8119C1EECC00AA859B /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 94B6CE8019C1EECC00AA859B /* Info.plist */; }; 94CCDD2219C1F29E00F9F148 /* libOAuth2Client.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D2AAC07E0554694100DB518D /* libOAuth2Client.a */; }; 94E5AC93122C097B00C7021A /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94E5AC92122C097B00C7021A /* Security.framework */; }; 99D8A7F913852C6E00E3073C /* NSData+NXOAuth2.h in Headers */ = {isa = PBXBuildFile; fileRef = 99D8A7F713852C6E00E3073C /* NSData+NXOAuth2.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -414,7 +413,7 @@ 0867D690FE84028FC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0460; + LastUpgradeCheck = 0600; ORGANIZATIONNAME = nxtbgthng; TargetAttributes = { 94B6CE6519C1D0A200AA859B = { @@ -456,7 +455,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 94B6CE8119C1EECC00AA859B /* Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -551,7 +549,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; DSTROOT = /tmp/OAuth2Client.dst; @@ -574,7 +571,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; DSTROOT = /tmp/OAuth2Client.dst; GCC_MODEL_TUNING = G5; @@ -593,7 +589,6 @@ 1DEB922308733DC00010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; GCC_C_LANGUAGE_STANDARD = c99; GCC_OPTIMIZATION_LEVEL = 0; GCC_WARN_ABOUT_RETURN_TYPE = YES; @@ -607,7 +602,6 @@ 1DEB922408733DC00010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; GCC_C_LANGUAGE_STANDARD = c99; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; @@ -621,7 +615,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; @@ -651,7 +644,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; From 88025e58a2d83283e1a08df0451132116834f17e Mon Sep 17 00:00:00 2001 From: Damien Rambout Date: Sun, 14 Sep 2014 13:15:36 +0200 Subject: [PATCH 2/6] Remove 64 bit conversion with precision loss warnings --- Sources/OAuth2Client/NXOAuth2PostBodyStream.m | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/OAuth2Client/NXOAuth2PostBodyStream.m b/Sources/OAuth2Client/NXOAuth2PostBodyStream.m index 8b156d84..beec8f71 100644 --- a/Sources/OAuth2Client/NXOAuth2PostBodyStream.m +++ b/Sources/OAuth2Client/NXOAuth2PostBodyStream.m @@ -30,8 +30,7 @@ - (id)initWithParameters:(NSDictionary *)postParameters; { self = [self init]; if (self) { - srandom(time(NULL)); - boundary = [[NSString alloc] initWithFormat:@"------------nx-oauth2%d", rand()]; + boundary = [[NSString alloc] initWithFormat:@"------------nx-oauth2%@", @(arc4random())]; numBytesTotal = 0; streamIndex = 0; @@ -88,7 +87,7 @@ - (NSArray *)streamsForParameters:(NSDictionary *)parameters contentLength:(unsi NSData *delimiterData = [delimiter dataUsingEncoding:NSUTF8StringEncoding]; NSData *contentHeaderData = [[part contentHeaders] dataUsingEncoding:NSUTF8StringEncoding]; - int dataLength = delimiterData.length + contentHeaderData.length; + NSUInteger dataLength = delimiterData.length + contentHeaderData.length; NSMutableData *headerData = [NSMutableData dataWithCapacity: dataLength]; [headerData appendData:delimiterData]; [headerData appendData:contentHeaderData]; @@ -146,7 +145,7 @@ - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len; if (currentStream == nil) return 0; - int result = [currentStream read:buffer maxLength:len]; + NSInteger result = [currentStream read:buffer maxLength:len]; if (result == 0) { if (streamIndex < contentStreams.count - 1) { From a923a0a4035863abd59359ff67e4bcd8037e40f0 Mon Sep 17 00:00:00 2001 From: Damien Rambout Date: Sun, 14 Sep 2014 13:20:16 +0200 Subject: [PATCH 3/6] Replace all integer string format keys into object format keys (converting values into numbers first) This is the modern Objc way. --- Sources/OAuth2Client/NXOAuth2AccessToken.m | 16 ++++++++-------- Sources/OAuth2Client/NXOAuth2AccountStore.m | 12 ++++++------ Sources/OAuth2Client/NXOAuth2Connection.m | 4 ++-- Sources/OAuth2Client/NXOAuth2Request.m | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Sources/OAuth2Client/NXOAuth2AccessToken.m b/Sources/OAuth2Client/NXOAuth2AccessToken.m index bedef7b8..582fb252 100644 --- a/Sources/OAuth2Client/NXOAuth2AccessToken.m +++ b/Sources/OAuth2Client/NXOAuth2AccessToken.m @@ -238,7 +238,7 @@ + (id)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider; result = (__bridge_transfer NSDictionary *)cfResult; if (status != noErr) { - NSAssert1(status == errSecItemNotFound, @"unexpected error while fetching token from keychain: %d", (int)status); + NSAssert1(status == errSecItemNotFound, @"unexpected error while fetching token from keychain: %@", (int)status); return nil; } @@ -257,7 +257,7 @@ - (void)storeInDefaultKeychainWithServiceProviderName:(NSString *)provider; nil]; [self removeFromDefaultKeychainWithServiceProviderName:provider]; OSStatus __attribute__((unused)) err = SecItemAdd((__bridge CFDictionaryRef)query, NULL); - NSAssert1(err == noErr, @"error while adding token to keychain: %d", (int)err); + NSAssert1(err == noErr, @"error while adding token to keychain: %@", (int)err); } - (void)removeFromDefaultKeychainWithServiceProviderName:(NSString *)provider; @@ -268,7 +268,7 @@ - (void)removeFromDefaultKeychainWithServiceProviderName:(NSString *)provider; serviceName, kSecAttrService, nil]; OSStatus __attribute__((unused)) err = SecItemDelete((__bridge CFDictionaryRef)query); - NSAssert1((err == noErr || err == errSecItemNotFound), @"error while deleting token from keychain: %d", (int)err); + NSAssert1((err == noErr || err == errSecItemNotFound), @"error while deleting token from keychain: %@", @(err)); } #else @@ -287,7 +287,7 @@ + (id)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider; NULL, &item); if (err != noErr) { - NSAssert1(err == errSecItemNotFound, @"unexpected error while fetching token from keychain: %d", err); + NSAssert1(err == errSecItemNotFound, @"unexpected error while fetching token from keychain: %@", @(err)); return nil; } @@ -314,7 +314,7 @@ + (id)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider; SecKeychainItemFreeContent(&list, password); } else { // TODO find out why this always works in i386 and always fails on ppc - NSLog(@"Error from SecKeychainItemCopyContent: %d", err); + NSLog(@"Error from SecKeychainItemCopyContent: %@", @(err)); return nil; } CFRelease(item); @@ -336,7 +336,7 @@ OSStatus __attribute__((unused))err = SecKeychainAddGenericPassword(NULL, [data bytes], NULL); - NSAssert1(err == noErr, @"error while adding token to keychain: %d", err); + NSAssert1(err == noErr, @"error while adding token to keychain: %@", @(err)); } - (void)removeFromDefaultKeychainWithServiceProviderName:(NSString *)provider; @@ -351,14 +351,14 @@ - (void)removeFromDefaultKeychainWithServiceProviderName:(NSString *)provider; NULL, NULL, &item); - NSAssert1((err == noErr || err == errSecItemNotFound), @"error while deleting token from keychain: %d", err); + NSAssert1((err == noErr || err == errSecItemNotFound), @"error while deleting token from keychain: %@", @(err)); if (err == noErr) { err = SecKeychainItemDelete(item); } if (item) { CFRelease(item); } - NSAssert1((err == noErr || err == errSecItemNotFound), @"error while deleting token from keychain: %d", err); + NSAssert1((err == noErr || err == errSecItemNotFound), @"error while deleting token from keychain: %@", @(err)); } #endif diff --git a/Sources/OAuth2Client/NXOAuth2AccountStore.m b/Sources/OAuth2Client/NXOAuth2AccountStore.m index 45815ec4..39bf09d8 100644 --- a/Sources/OAuth2Client/NXOAuth2AccountStore.m +++ b/Sources/OAuth2Client/NXOAuth2AccountStore.m @@ -643,7 +643,7 @@ + (void)removeFromDefaultKeychain; serviceName, kSecAttrService, nil]; OSStatus __attribute__((unused)) err = SecItemDelete((__bridge CFDictionaryRef)query); - NSAssert1((err == noErr || err == errSecItemNotFound), @"Error while deleting token from keychain: %zd", err); + NSAssert1((err == noErr || err == errSecItemNotFound), @"Error while deleting token from keychain: %zd", @(err)); } @@ -663,7 +663,7 @@ + (NSDictionary *)accountsFromDefaultKeychain; NULL, &item); if (err != noErr) { - NSAssert1(err == errSecItemNotFound, @"Unexpected error while fetching accounts from keychain: %d", err); + NSAssert1(err == errSecItemNotFound, @"Unexpected error while fetching accounts from keychain: %@", @(err)); return nil; } @@ -690,7 +690,7 @@ + (NSDictionary *)accountsFromDefaultKeychain; SecKeychainItemFreeContent(&list, password); } else { // TODO find out why this always works in i386 and always fails on ppc - NSLog(@"Error from SecKeychainItemCopyContent: %d", err); + NSLog(@"Error from SecKeychainItemCopyContent: %@", @(err)); return nil; } CFRelease(item); @@ -714,7 +714,7 @@ OSStatus __attribute__((unused))err = SecKeychainAddGenericPassword(NULL, [data bytes], NULL); - NSAssert1(err == noErr, @"Error while storing accounts in keychain: %d", err); + NSAssert1(err == noErr, @"Error while storing accounts in keychain: %@", @(err)); } + (void)removeFromDefaultKeychain; @@ -730,14 +730,14 @@ + (void)removeFromDefaultKeychain; NULL, NULL, &item); - NSAssert1((err == noErr || err == errSecItemNotFound), @"Error while deleting accounts from keychain: %d", err); + NSAssert1((err == noErr || err == errSecItemNotFound), @"Error while deleting accounts from keychain: %@", @(err)); if (err == noErr) { err = SecKeychainItemDelete(item); } if (item) { CFRelease(item); } - NSAssert1((err == noErr || err == errSecItemNotFound), @"Error while deleting accounts from keychain: %d", err); + NSAssert1((err == noErr || err == errSecItemNotFound), @"Error while deleting accounts from keychain: %@", @(err)); } #endif diff --git a/Sources/OAuth2Client/NXOAuth2Connection.m b/Sources/OAuth2Client/NXOAuth2Connection.m index a324850b..db188814 100644 --- a/Sources/OAuth2Client/NXOAuth2Connection.m +++ b/Sources/OAuth2Client/NXOAuth2Connection.m @@ -237,7 +237,7 @@ - (void)applyParameters:(NSDictionary *)parameters onRequest:(NSMutableURLReques NSInputStream *postBodyStream = [[NXOAuth2PostBodyStream alloc] initWithParameters:parameters]; contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",[(NXOAuth2PostBodyStream *)postBodyStream boundary]]; - NSString *contentLength = [NSString stringWithFormat:@"%lld", [(NXOAuth2PostBodyStream *)postBodyStream length]]; + NSString *contentLength = [@([(NXOAuth2PostBodyStream *)postBodyStream length]) stringValue]; [aRequest setValue:contentType forHTTPHeaderField:@"Content-Type"]; [aRequest setValue:contentLength forHTTPHeaderField:@"Content-Length"]; @@ -474,7 +474,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection; } } - NSString *localizedError = [NSString stringWithFormat:NSLocalizedString(@"HTTP Error: %d", @"NXOAuth2HTTPErrorDomain description"), self.statusCode]; + NSString *localizedError = [NSString stringWithFormat:NSLocalizedString(@"HTTP Error: %@", @"NXOAuth2HTTPErrorDomain description"), self.statusCode]; NSDictionary *errorUserInfo = [NSDictionary dictionaryWithObject:localizedError forKey:NSLocalizedDescriptionKey]; NSError *error = [NSError errorWithDomain:NXOAuth2HTTPErrorDomain code:self.statusCode diff --git a/Sources/OAuth2Client/NXOAuth2Request.m b/Sources/OAuth2Client/NXOAuth2Request.m index 6ea973c0..c735c50e 100644 --- a/Sources/OAuth2Client/NXOAuth2Request.m +++ b/Sources/OAuth2Client/NXOAuth2Request.m @@ -163,7 +163,7 @@ - (void)applyParameters:(NSDictionary *)someParameters onRequest:(NSMutableURLRe NSInputStream *postBodyStream = [[NXOAuth2PostBodyStream alloc] initWithParameters:parameters]; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", [(NXOAuth2PostBodyStream *)postBodyStream boundary]]; - NSString *contentLength = [NSString stringWithFormat:@"%llu", [(NXOAuth2PostBodyStream *)postBodyStream length]]; + NSString *contentLength = [@([(NXOAuth2PostBodyStream *)postBodyStream length]) stringValue]; [aRequest setValue:contentType forHTTPHeaderField:@"Content-Type"]; [aRequest setValue:contentLength forHTTPHeaderField:@"Content-Length"]; From 9f5140be7a8d44364399a531cf6d6cc2bfb239af Mon Sep 17 00:00:00 2001 From: Damien Rambout Date: Sun, 29 Mar 2015 22:22:53 +0200 Subject: [PATCH 4/6] Fix some format keys for integer values --- Sources/OAuth2Client/NXOAuth2AccessToken.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/OAuth2Client/NXOAuth2AccessToken.m b/Sources/OAuth2Client/NXOAuth2AccessToken.m index 582fb252..1e211fcf 100644 --- a/Sources/OAuth2Client/NXOAuth2AccessToken.m +++ b/Sources/OAuth2Client/NXOAuth2AccessToken.m @@ -238,7 +238,7 @@ + (id)tokenFromDefaultKeychainWithServiceProviderName:(NSString *)provider; result = (__bridge_transfer NSDictionary *)cfResult; if (status != noErr) { - NSAssert1(status == errSecItemNotFound, @"unexpected error while fetching token from keychain: %@", (int)status); + NSAssert1(status == errSecItemNotFound, @"unexpected error while fetching token from keychain: %@", @(status)); return nil; } @@ -257,7 +257,7 @@ - (void)storeInDefaultKeychainWithServiceProviderName:(NSString *)provider; nil]; [self removeFromDefaultKeychainWithServiceProviderName:provider]; OSStatus __attribute__((unused)) err = SecItemAdd((__bridge CFDictionaryRef)query, NULL); - NSAssert1(err == noErr, @"error while adding token to keychain: %@", (int)err); + NSAssert1(err == noErr, @"error while adding token to keychain: %@", @(err)); } - (void)removeFromDefaultKeychainWithServiceProviderName:(NSString *)provider; From 0ccffe2f995a2e83a2e0e60877320bbbd6b1120e Mon Sep 17 00:00:00 2001 From: Damien Rambout Date: Sun, 29 Mar 2015 22:25:07 +0200 Subject: [PATCH 5/6] Restore Info.plist in project --- OAuth2Client.xcodeproj/project.pbxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/OAuth2Client.xcodeproj/project.pbxproj b/OAuth2Client.xcodeproj/project.pbxproj index 0fdf9773..1cbab44e 100644 --- a/OAuth2Client.xcodeproj/project.pbxproj +++ b/OAuth2Client.xcodeproj/project.pbxproj @@ -53,6 +53,7 @@ 942FFD7E12315EFF00E6C65E /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94E5AC92122C097B00C7021A /* Security.framework */; }; 945A500D123F7BAE00A6F2EB /* NXOAuth2ClientDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 824D5A6D123F68A8001177D5 /* NXOAuth2ClientDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 94B6CE7219C1D3E400AA859B /* NXOAuth2PostBodyStreamSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 94B6CE7119C1D3E400AA859B /* NXOAuth2PostBodyStreamSpec.m */; }; + 94B6CE8119C1EECC00AA859B /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 94B6CE8019C1EECC00AA859B /* Info.plist */; }; 94CCDD2219C1F29E00F9F148 /* libOAuth2Client.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D2AAC07E0554694100DB518D /* libOAuth2Client.a */; }; 94E5AC93122C097B00C7021A /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94E5AC92122C097B00C7021A /* Security.framework */; }; 99D8A7F913852C6E00E3073C /* NSData+NXOAuth2.h in Headers */ = {isa = PBXBuildFile; fileRef = 99D8A7F713852C6E00E3073C /* NSData+NXOAuth2.h */; settings = {ATTRIBUTES = (Public, ); }; }; From 74bd8103608964252e0246c6610b78fe2537b114 Mon Sep 17 00:00:00 2001 From: Damien Rambout Date: Sun, 29 Mar 2015 22:34:13 +0200 Subject: [PATCH 6/6] Restore Info.plist in project --- OAuth2Client.xcodeproj/project.pbxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/OAuth2Client.xcodeproj/project.pbxproj b/OAuth2Client.xcodeproj/project.pbxproj index 1cbab44e..56ad49bb 100644 --- a/OAuth2Client.xcodeproj/project.pbxproj +++ b/OAuth2Client.xcodeproj/project.pbxproj @@ -456,6 +456,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 94B6CE8119C1EECC00AA859B /* Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; };