Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Updates #20

Open
wants to merge 1 commit into from

1 participant

@pcperini
  1. I added conditionals where iOS/OS X specific things were occurring, allowing users to drop in the code as-is into either iOS or Mac OS X projects.

  2. I ARCified the code. Most of this work was done by the Xcode ARC Refactor Engine

  3. I added blocks to OADataFetcher, in an attempt to clean up some of the fractured callback mechanisms.

Some of these changes would admittedly push up the minimum SDK requirements for the project, but they are well worth it for my needs, and I'm sure they are for others' as well.

Patrick Perini Usability Upgrade
ARCified code. Automatic cross-compiling for iOS/OS X. Added
finish/fail blocks for OADataFetcher.
20bd44e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 8, 2012
  1. Usability Upgrade

    Patrick Perini authored
    ARCified code. Automatic cross-compiling for iOS/OS X. Added
    finish/fail blocks for OADataFetcher.
This page is out of date. Refresh to see the latest.
Showing with 122 additions and 192 deletions.
  1. 0  Categories/NSMutableURLRequest+Parameters.h
  2. +4 −4 Categories/NSMutableURLRequest+Parameters.m
  3. 0  Categories/NSString+URLEncoding.h
  4. +9 −9 Categories/NSString+URLEncoding.m
  5. 0  Categories/NSURL+Base.h
  6. 0  Categories/NSURL+Base.m
  7. 0  Crypto/Base64Transcoder.c
  8. 0  Crypto/Base64Transcoder.h
  9. +3 −2 Crypto/hmac.c
  10. 0  Crypto/hmac.h
  11. 0  Crypto/sha1.c
  12. 0  Crypto/sha1.h
  13. 0  OAAttachment.h
  14. +0 −7 OAAttachment.m
  15. +5 −5 OACall.h
  16. +6 −18 OACall.m
  17. 0  OAConsumer.h
  18. +0 −5 OAConsumer.m
  19. +6 −0 OADataFetcher.h
  20. +28 −15 OADataFetcher.m
  21. 0  OAHMAC_SHA1SignatureProvider.h
  22. +3 −5 OAHMAC_SHA1SignatureProvider.m
  23. +3 −1 OAMutableURLRequest.h
  24. +5 −27 OAMutableURLRequest.m
  25. 0  OAPlaintextSignatureProvider.h
  26. 0  OAPlaintextSignatureProvider.m
  27. 0  OAProblem.h
  28. +12 −17 OAProblem.m
  29. 0  OARequestParameter.h
  30. +1 −7 OARequestParameter.m
  31. +4 −4 OAServiceTicket.h
  32. +4 −10 OAServiceTicket.m
  33. 0  OASignatureProviding.h
  34. +6 −6 OAToken.h
  35. +3 −12 OAToken.m
  36. +1 −1  OATokenManager.h
  37. +19 −37 OATokenManager.m
  38. 0  OAuthConsumer.h
View
0  Categories/NSMutableURLRequest+Parameters.h 100644 → 100755
File mode changed
View
8 Categories/NSMutableURLRequest+Parameters.m 100644 → 100755
@@ -40,7 +40,7 @@ - (NSArray *)parameters {
if ([[self HTTPMethod] isEqualToString:@"GET"] || [[self HTTPMethod] isEqualToString:@"DELETE"]) {
encodedParameters = [[self URL] query];
} else {
- encodedParameters = [[[NSString alloc] initWithData:[self HTTPBody] encoding:NSASCIIStringEncoding] autorelease];
+ encodedParameters = [[NSString alloc] initWithData:[self HTTPBody] encoding:NSASCIIStringEncoding];
}
}
@@ -56,7 +56,7 @@ - (NSArray *)parameters {
OARequestParameter *parameter = [[OARequestParameter alloc] initWithName:[[encodedPairElements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
value:[[encodedPairElements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[requestParameters addObject:parameter];
- [parameter release];
+ parameter = nil;
}
return requestParameters;
@@ -64,7 +64,7 @@ - (NSArray *)parameters {
- (void)setParameters:(NSArray *)parameters
{
- NSMutableArray *pairs = [[[NSMutableArray alloc] initWithCapacity:[parameters count]] autorelease];
+ NSMutableArray *pairs = [[NSMutableArray alloc] initWithCapacity:[parameters count]];
for (OARequestParameter *requestParameter in parameters) {
[pairs addObject:[requestParameter URLEncodedNameValuePair]];
}
@@ -107,7 +107,7 @@ - (void)attachFileWithName:(NSString *)name filename:(NSString*)filename content
[bodyData appendData:[[[@"\r\n--" stringByAppendingString:Boundary] stringByAppendingString:@"--"] dataUsingEncoding:NSUTF8StringEncoding]];
[self setValue:[NSString stringWithFormat:@"%d", [bodyData length]] forHTTPHeaderField:@"Content-Length"];
[self setHTTPBody:bodyData];
- [bodyData release];
+ bodyData = nil;
}
@end
View
0  Categories/NSString+URLEncoding.h 100644 → 100755
File mode changed
View
18 Categories/NSString+URLEncoding.m
@@ -29,30 +29,30 @@
@implementation NSString (OAURLEncodingAdditions)
- (NSString *)encodedURLString {
- NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
- (CFStringRef)self,
+ NSString *result = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
+ (__bridge CFStringRef)self,
NULL, // characters to leave unescaped (NULL = all escaped sequences are replaced)
CFSTR("?=&+"), // legal URL characters to be escaped (NULL = all legal characters are replaced)
kCFStringEncodingUTF8); // encoding
- return [result autorelease];
+ return result;
}
- (NSString *)encodedURLParameterString {
- NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
- (CFStringRef)self,
+ NSString *result = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
+ (__bridge CFStringRef)self,
NULL,
CFSTR(":/=,!$&'()*+;[]@#?"),
kCFStringEncodingUTF8);
- return [result autorelease];
+ return result;
}
- (NSString *)decodedURLString {
- NSString *result = (NSString*)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
- (CFStringRef)self,
+ NSString *result = (__bridge_transfer NSString*)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
+ (__bridge CFStringRef)self,
CFSTR(""),
kCFStringEncodingUTF8);
- return [result autorelease];
+ return result;
}
View
0  Categories/NSURL+Base.h 100644 → 100755
File mode changed
View
0  Categories/NSURL+Base.m 100644 → 100755
File mode changed
View
0  Crypto/Base64Transcoder.c 100644 → 100755
File mode changed
View
0  Crypto/Base64Transcoder.h 100644 → 100755
File mode changed
View
5 Crypto/hmac.c 100644 → 100755
@@ -33,6 +33,7 @@
#include <stdlib.h>
#include <string.h>
+void hmac_sha1(const u_int8_t *inText, size_t inTextLength, u_int8_t* inKey, size_t inKeyLength, u_int8_t *outDigest);
void hmac_sha1(const u_int8_t *inText, size_t inTextLength, u_int8_t* inKey, size_t inKeyLength, u_int8_t *outDigest)
{
#define B 64
@@ -46,7 +47,7 @@ u_int8_t k_opad[B + 1]; /* outer padding - key XORd with opad */
if (inKeyLength > B)
{
SHA1Init(&theSHA1Context);
- SHA1Update(&theSHA1Context, inKey, inKeyLength);
+ SHA1Update(&theSHA1Context, inKey, (u_int32_t)inKeyLength);
SHA1Final(inKey, &theSHA1Context);
inKeyLength = L;
}
@@ -70,7 +71,7 @@ for (i = 0; i < B; i++)
*/
SHA1Init(&theSHA1Context); /* init context for 1st pass */
SHA1Update(&theSHA1Context, k_ipad, B); /* start with inner pad */
-SHA1Update(&theSHA1Context, (u_int8_t *)inText, inTextLength); /* then text of datagram */
+SHA1Update(&theSHA1Context, (u_int8_t *)inText, (u_int32_t)inTextLength); /* then text of datagram */
SHA1Final((u_int8_t *)outDigest, &theSHA1Context); /* finish up 1st pass */
/*
View
0  Crypto/hmac.h 100644 → 100755
File mode changed
View
0  Crypto/sha1.c 100644 → 100755
File mode changed
View
0  Crypto/sha1.h 100644 → 100755
File mode changed
View
0  OAAttachment.h 100644 → 100755
File mode changed
View
7 OAAttachment.m
@@ -22,12 +22,5 @@ - (id)initWithName:(NSString *)aName filename:(NSString *)aFilename contentType:
return self;
}
-- (void)dealloc{
- [name release];
- [fileName release];
- [contentType release];
- [data release];
- [super dealloc];
-}
@end
View
10 OACall.h
@@ -25,10 +25,10 @@
@class OAServiceTicket;
@interface OACall : NSObject {
- NSURL *url;
- NSString *method;
- NSArray *parameters;
- NSDictionary *files;
+ NSURL *__weak url;
+ NSString *__weak method;
+ NSArray *__weak parameters;
+ NSDictionary *__weak files;
NSObject <OACallDelegate> *delegate;
SEL finishedSelector;
OADataFetcher *fetcher;
@@ -40,7 +40,7 @@
@property(readonly) NSString *method;
@property(readonly) NSArray *parameters;
@property(readonly) NSDictionary *files;
-@property(nonatomic, retain) OAServiceTicket *ticket;
+@property(nonatomic, strong) OAServiceTicket *ticket;
- (id)init;
- (id)initWithURL:(NSURL *)aURL;
View
24 OACall.m
@@ -71,10 +71,10 @@ - (id)initWithURL:(NSURL *)aURL
parameters:(NSArray *)theParameters
files:(NSDictionary*)theFiles {
if ((self = [super init])) {
- url = [aURL retain];
- method = [aMethod retain];
- parameters = [theParameters retain];
- files = [theFiles retain];
+ url = aURL;
+ method = aMethod;
+ parameters = theParameters;
+ files = theFiles;
fetcher = nil;
request = nil;
}
@@ -82,21 +82,10 @@ - (id)initWithURL:(NSURL *)aURL
return self;
}
-- (void)dealloc {
- [url release];
- [method release];
- [parameters release];
- [files release];
- [fetcher release];
- [request release];
- [ticket release];
- [super dealloc];
-}
- (void)callFailed:(OAServiceTicket *)aTicket withError:(NSError *)error {
NSLog(@"error body: %@", aTicket.body);
self.ticket = aTicket;
- [aTicket release];
OAProblem *problem = [OAProblem problemWithResponseBody:ticket.body];
if (problem) {
[delegate call:self failedWithProblem:problem];
@@ -107,13 +96,12 @@ - (void)callFailed:(OAServiceTicket *)aTicket withError:(NSError *)error {
- (void)callFinished:(OAServiceTicket *)aTicket withData:(NSData *)data {
self.ticket = aTicket;
- [aTicket release];
if (ticket.didSucceed) {
// NSLog(@"Call body: %@", ticket.body);
- [delegate performSelector:finishedSelector withObject:self withObject:ticket.body];
+ objc_msgSend(delegate, finishedSelector, self, ticket.body);
} else {
// NSLog(@"Failed call body: %@", ticket.body);
- [self callFailed:[ticket retain] withError:nil];
+ [self callFailed:ticket withError:nil];
}
}
View
0  OAConsumer.h 100644 → 100755
File mode changed
View
5 OAConsumer.m
@@ -39,11 +39,6 @@ - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret {
return self;
}
-- (void)dealloc {
- [key release];
- [secret release];
- [super dealloc];
-}
- (BOOL)isEqual:(id)object {
if ([object isKindOfClass:[self class]]) {
View
6 OADataFetcher.h 100644 → 100755
@@ -24,9 +24,12 @@
// THE SOFTWARE.
#import <Foundation/Foundation.h>
+#import <objc/message.h>
#import "OAMutableURLRequest.h"
#import "OAServiceTicket.h"
+typedef void(^OAFinishBlock) (OAServiceTicket *ticket, NSData *data);
+typedef void(^OAFailureBlock)(OAServiceTicket *ticket, NSError *error);
@interface OADataFetcher : NSObject {
@private
@@ -37,8 +40,11 @@
id delegate;
SEL didFinishSelector;
SEL didFailSelector;
+ OAFailureBlock didFailBlock;
+ OAFinishBlock didFinishBlock;
}
+- (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest didFinishBlock:(OAFinishBlock)finishBlock didFailBlock:(OAFailureBlock)failBlock;
- (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector;
@end
View
43 OADataFetcher.m
@@ -36,18 +36,10 @@ - (id)init {
return self;
}
-- (void)dealloc {
- [connection release];
- [response release];
- [responseData release];
- [request release];
- [super dealloc];
-}
/* Protocol for async URL loading */
- (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLResponse *)aResponse {
- [response release];
- response = [aResponse retain];
+ response = aResponse;
[responseData setLength:0];
}
@@ -57,8 +49,14 @@ - (void)connection:(NSURLConnection *)aConnection didFailWithError:(NSError *)er
data:responseData
didSucceed:NO];
- [delegate performSelector:didFailSelector withObject:ticket withObject:error];
- [ticket release];
+ if (didFailBlock)
+ {
+ didFailBlock(ticket, error);
+ }
+ else if(didFailSelector)
+ {
+ objc_msgSend(delegate, didFailSelector, ticket, error);
+ }
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
@@ -71,13 +69,18 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
data:responseData
didSucceed:[(NSHTTPURLResponse *)response statusCode] < 400];
- [delegate performSelector:didFinishSelector withObject:ticket withObject:responseData];
- [ticket release];
+ if (didFinishBlock)
+ {
+ didFinishBlock(ticket, responseData);
+ }
+ else
+ {
+ objc_msgSend(delegate, didFinishSelector, ticket, responseData);
+ }
}
- (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector {
- [request release];
- request = [aRequest retain];
+ request = aRequest;
delegate = aDelegate;
didFinishSelector = finishSelector;
didFailSelector = failSelector;
@@ -87,4 +90,14 @@ - (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDeleg
connection = [[NSURLConnection alloc] initWithRequest:aRequest delegate:self];
}
+- (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest didFinishBlock:(OAFinishBlock)finishBlock didFailBlock:(OAFailureBlock)failBlock {
+ request = aRequest;
+ didFinishBlock = finishBlock;
+ didFailBlock = failBlock;
+
+ [request prepare];
+
+ connection = [[NSURLConnection alloc] initWithRequest:aRequest delegate:self];
+}
+
@end
View
0  OAHMAC_SHA1SignatureProvider.h 100644 → 100755
File mode changed
View
8 OAHMAC_SHA1SignatureProvider.m
@@ -36,12 +36,10 @@ - (NSString *)name {
}
- (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret {
- NSData *secretData = [[secret dataUsingEncoding:NSUTF8StringEncoding] retain];
- NSData *clearTextData = [[text dataUsingEncoding:NSUTF8StringEncoding] retain];
+ NSData *secretData = [secret dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *clearTextData = [text dataUsingEncoding:NSUTF8StringEncoding];
unsigned char result[20];
hmac_sha1((unsigned char *)[clearTextData bytes], [clearTextData length], (unsigned char *)[secretData bytes], [secretData length], result);
- [secretData release];
- [clearTextData release];
//Base64 Encoding
@@ -50,7 +48,7 @@ - (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret {
Base64EncodeData(result, 20, base64Result, &theResultLength);
NSData *theData = [NSData dataWithBytes:base64Result length:theResultLength];
- NSString *base64EncodedResult = [[[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding] autorelease];
+ NSString *base64EncodedResult = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding];
return base64EncodedResult;
}
View
4 OAMutableURLRequest.h
@@ -38,7 +38,7 @@
OAConsumer *consumer;
OAToken *token;
NSString *realm;
- NSString *signature;
+ NSString *__weak signature;
id<OASignatureProviding> signatureProvider;
NSString *nonce;
NSString *timestamp;
@@ -46,6 +46,8 @@
@property(readonly) NSString *signature;
@property(readonly) NSString *nonce;
+NSInteger normalize(id obj1, id obj2, void *context);
+
- (id)initWithURL:(NSURL *)aUrl
consumer:(OAConsumer *)aConsumer
token:(OAToken *)aToken
View
32 OAMutableURLRequest.m
@@ -47,13 +47,13 @@ - (id)initWithURL:(NSURL *)aUrl
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:10.0])) {
- consumer = [aConsumer retain];
+ consumer = aConsumer;
// empty token for Unauthorized Request Token transaction
if (aToken == nil) {
token = [[OAToken alloc] init];
} else {
- token = [aToken retain];
+ token = aToken;
}
if (aRealm == nil) {
@@ -66,7 +66,7 @@ - (id)initWithURL:(NSURL *)aUrl
if (aProvider == nil) {
signatureProvider = [[OAHMAC_SHA1SignatureProvider alloc] init];
} else {
- signatureProvider = [aProvider retain];
+ signatureProvider = aProvider;
}
[self _generateTimestamp];
@@ -118,24 +118,19 @@ - (void)prepare {
[chunks addObject:@"oauth_version=\"1.0\""];
NSString *oauthHeader = [NSString stringWithFormat:@"OAuth %@", [chunks componentsJoinedByString:@", "]];
- [chunks release];
[self setValue:oauthHeader forHTTPHeaderField:@"Authorization"];
}
- (void)_generateTimestamp {
- [timestamp release];
+ timestamp = nil;
timestamp = [[NSString alloc]initWithFormat:@"%d", time(NULL)];
}
- (void)_generateNonce {
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
- [NSMakeCollectable(theUUID) autorelease];
- if (nonce) {
- CFRelease(nonce);
- }
- nonce = (NSString *)string;
+ nonce = (__bridge_transfer NSString *)string;
}
NSInteger normalize(id obj1, id obj2, void *context)
@@ -170,19 +165,14 @@ - (NSString *)_signatureBaseString {
parameter = [[OARequestParameter alloc] initWithName:@"oauth_consumer_key" value:consumer.key];
[parameterPairs addObject:[parameter URLEncodedNameValuePair]];
- [parameter release];
parameter = [[OARequestParameter alloc] initWithName:@"oauth_signature_method" value:[signatureProvider name]];
[parameterPairs addObject:[parameter URLEncodedNameValuePair]];
- [parameter release];
parameter = [[OARequestParameter alloc] initWithName:@"oauth_timestamp" value:timestamp];
[parameterPairs addObject:[parameter URLEncodedNameValuePair]];
- [parameter release];
parameter = [[OARequestParameter alloc] initWithName:@"oauth_nonce" value:nonce];
[parameterPairs addObject:[parameter URLEncodedNameValuePair]];
- [parameter release];
parameter = [[OARequestParameter alloc] initWithName:@"oauth_version" value:@"1.0"] ;
[parameterPairs addObject:[parameter URLEncodedNameValuePair]];
- [parameter release];
for(NSString *k in tokenParameters) {
[parameterPairs addObject:[[OARequestParameter requestParameter:k value:[tokenParameters objectForKey:k]] URLEncodedNameValuePair]];
@@ -198,7 +188,6 @@ - (NSString *)_signatureBaseString {
NSArray *sortedPairs = [parameterPairs sortedArrayUsingFunction:normalize context:NULL];
NSString *normalizedRequestParameters = [sortedPairs componentsJoinedByString:@"&"];
- [parameterPairs release];
// NSLog(@"Normalized: %@", normalizedRequestParameters);
// OAuth Spec, Section 9.1.2 "Concatenate Request Elements"
return [NSString stringWithFormat:@"%@&%@&%@",
@@ -207,16 +196,5 @@ - (NSString *)_signatureBaseString {
[normalizedRequestParameters encodedURLString]];
}
-- (void) dealloc
-{
- [consumer release];
- [token release];
- [signatureProvider release];
- [timestamp release];
- if (nonce) {
- CFRelease(nonce);
- }
- [super dealloc];
-}
@end
View
0  OAPlaintextSignatureProvider.h 100644 → 100755
File mode changed
View
0  OAPlaintextSignatureProvider.m 100644 → 100755
File mode changed
View
0  OAProblem.h 100644 → 100755
File mode changed
View
29 OAProblem.m
@@ -54,15 +54,10 @@ - (id)initWithResponseBody:(NSString *) response
return nil;
}
-- (void)dealloc
-{
- [problem release];
- [super dealloc];
-}
+ (OAProblem *)problemWithResponseBody:(NSString *) response
{
- return [[[OAProblem alloc] initWithResponseBody:response] autorelease];
+ return [[OAProblem alloc] initWithResponseBody:response];
}
+ (NSArray *)validProblems
@@ -109,7 +104,7 @@ - (BOOL)isEqualTo:(id) aProblem
}
- (int)code {
- return [[[self class] validProblems] indexOfObject:problem];
+ return (int)[[[self class] validProblems] indexOfObject:problem];
}
- (NSString *)description
@@ -121,52 +116,52 @@ - (NSString *)description
+ (OAProblem *)SignatureMethodRejected
{
- return [[[OAProblem alloc] initWithPointer:signature_method_rejected] autorelease];
+ return [[OAProblem alloc] initWithPointer:signature_method_rejected];
}
+ (OAProblem *)ParameterAbsent
{
- return [[[OAProblem alloc] initWithPointer:parameter_absent] autorelease];
+ return [[OAProblem alloc] initWithPointer:parameter_absent];
}
+ (OAProblem *)VersionRejected
{
- return [[[OAProblem alloc] initWithPointer:version_rejected] autorelease];
+ return [[OAProblem alloc] initWithPointer:version_rejected];
}
+ (OAProblem *)ConsumerKeyUnknown
{
- return [[[OAProblem alloc] initWithPointer:consumer_key_unknown] autorelease];
+ return [[OAProblem alloc] initWithPointer:consumer_key_unknown];
}
+ (OAProblem *)TokenRejected
{
- return [[[OAProblem alloc] initWithPointer:token_rejected] autorelease];
+ return [[OAProblem alloc] initWithPointer:token_rejected];
}
+ (OAProblem *)SignatureInvalid
{
- return [[[OAProblem alloc] initWithPointer:signature_invalid] autorelease];
+ return [[OAProblem alloc] initWithPointer:signature_invalid];
}
+ (OAProblem *)NonceUsed
{
- return [[[OAProblem alloc] initWithPointer:nonce_used] autorelease];
+ return [[OAProblem alloc] initWithPointer:nonce_used];
}
+ (OAProblem *)TimestampRefused
{
- return [[[OAProblem alloc] initWithPointer:timestamp_refused] autorelease];
+ return [[OAProblem alloc] initWithPointer:timestamp_refused];
}
+ (OAProblem *)TokenExpired
{
- return [[[OAProblem alloc] initWithPointer:token_expired] autorelease];
+ return [[OAProblem alloc] initWithPointer:token_expired];
}
+ (OAProblem *)TokenNotRenewable
{
- return [[[OAProblem alloc] initWithPointer:token_not_renewable] autorelease];
+ return [[OAProblem alloc] initWithPointer:token_not_renewable];
}
@end
View
0  OARequestParameter.h 100644 → 100755
File mode changed
View
8 OARequestParameter.m
@@ -38,12 +38,6 @@ - (id)initWithName:(NSString *)aName value:(NSString *)aValue {
return self;
}
-- (void)dealloc
-{
- [name release];
- [value release];
- [super dealloc];
-}
- (NSString *)URLEncodedName {
return self.name;
@@ -74,7 +68,7 @@ - (BOOL)isEqualToRequestParameter:(OARequestParameter *)parameter {
+ (id)requestParameter:(NSString *)aName value:(NSString *)aValue
{
- return [[[self alloc] initWithName:aName value:aValue] autorelease];
+ return [[self alloc] initWithName:aName value:aValue];
}
@end
View
8 OAServiceTicket.h
@@ -30,16 +30,16 @@
@interface OAServiceTicket : NSObject {
@private
- OAMutableURLRequest *request;
- NSURLResponse *response;
- NSData *data;
+ OAMutableURLRequest *__weak request;
+ NSURLResponse *__weak response;
+ NSData *__weak data;
BOOL didSucceed;
}
@property(readonly) OAMutableURLRequest *request;
@property(readonly) NSURLResponse *response;
@property(readonly) NSData *data;
@property(readonly) BOOL didSucceed;
-@property(readonly) NSString *body;
+@property(weak, readonly) NSString *body;
- (id)initWithRequest:(OAMutableURLRequest *)aRequest response:(NSURLResponse *)aResponse data:(NSData *)aData didSucceed:(BOOL)success;
View
14 OAServiceTicket.m
@@ -32,20 +32,14 @@ @implementation OAServiceTicket
- (id)initWithRequest:(OAMutableURLRequest *)aRequest response:(NSURLResponse *)aResponse data:(NSData *)aData didSucceed:(BOOL)success {
if ((self = [super init])) {
- request = [aRequest retain];
- response = [aResponse retain];
- data = [aData retain];
+ request = aRequest;
+ response = aResponse;
+ data = aData;
didSucceed = success;
}
return self;
}
-- (void)dealloc {
- [request release];
- [response release];
- [data release];
- [super dealloc];
-}
- (NSString *)body
{
@@ -53,7 +47,7 @@ - (NSString *)body
return nil;
}
- return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
+ return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
@end
View
0  OASignatureProviding.h 100644 → 100755
File mode changed
View
12 OAToken.h
@@ -36,12 +36,12 @@
BOOL renewable;
BOOL forRenewal;
}
-@property(retain, readwrite) NSString *key;
-@property(retain, readwrite) NSString *secret;
-@property(retain, readwrite) NSString *session;
-@property(retain, readwrite) NSNumber *duration;
-@property(retain, readwrite) NSString *verifier;
-@property(nonatomic, retain, readwrite) NSDictionary *attributes;
+@property(strong, readwrite) NSString *key;
+@property(strong, readwrite) NSString *secret;
+@property(strong, readwrite) NSString *session;
+@property(strong, readwrite) NSNumber *duration;
+@property(strong, readwrite) NSString *verifier;
+@property(nonatomic, strong, readwrite) NSDictionary *attributes;
@property(readwrite, getter=isForRenewal) BOOL forRenewal;
- (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret;
View
15 OAToken.m
@@ -61,7 +61,7 @@ - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret session:(NSString
self.session = aSession;
self.duration = aDuration;
self.attributes = theAttributes;
- created = [creation retain];
+ created = creation;
renewable = renew;
forRenewal = NO;
}
@@ -127,7 +127,6 @@ - (id)initWithUserDefaultsUsingServiceProviderName:(const NSString *)provider pr
renewable = [[OAToken loadSetting:@"renewable" provider:provider prefix:prefix] boolValue];
if (![self isValid]) {
- [self autorelease];
return nil;
}
}
@@ -138,13 +137,7 @@ - (id)initWithUserDefaultsUsingServiceProviderName:(const NSString *)provider pr
#pragma mark dealloc
- (void)dealloc {
- self.key = nil;
- self.secret = nil;
- self.session = nil;
- self.duration = nil;
- self.verifier = nil;
self.attributes = nil;
- [super dealloc];
}
#pragma mark settings
@@ -203,7 +196,6 @@ - (void)setAttribute:(const NSString *)aKey value:(const NSString *)aAttribute {
}
- (void)setAttributes:(NSDictionary *)theAttributes {
- [attributes release];
if (theAttributes) {
attributes = [[NSMutableDictionary alloc] initWithDictionary:theAttributes];
}else {
@@ -226,7 +218,6 @@ - (NSString *)attributeString {
[chunks addObject:[NSString stringWithFormat:@"%@:%@", aKey, [attributes objectForKey:aKey]]];
}
NSString *attrs = [chunks componentsJoinedByString:@";"];
- [chunks release];
return attrs;
}
@@ -242,7 +233,7 @@ - (void)setAttributesWithString:(NSString *)theAttributes
- (NSDictionary *)parameters
{
- NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease];
+ NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
if (key) {
[params setObject:key forKey:@"oauth_token"];
@@ -345,7 +336,7 @@ + (NSDictionary *)attributesWithString:(NSString *)theAttributes {
NSArray *elements = [pair componentsSeparatedByString:@":"];
[dct setObject:[elements objectAtIndex:1] forKey:[elements objectAtIndex:0]];
}
- return [dct autorelease];
+ return dct;
}
#pragma mark description
View
2  OATokenManager.h 100644 → 100755
@@ -7,7 +7,7 @@
// bynotes.com
#import <Foundation/Foundation.h>
-
+#import <objc/message.h>
#import "OACall.h"
@class OATokenManager;
View
56 OATokenManager.m
@@ -52,10 +52,10 @@ - (id)initWithConsumer:(OAConsumer *)aConsumer token:(OAToken *)aToken oauthBase
delegate:(NSObject <OATokenManagerDelegate> *)aDelegate {
if ((self = [super init])) {
- consumer = [aConsumer retain];
+ consumer = aConsumer;
acToken = nil;
reqToken = nil;
- initialToken = [aToken retain];
+ initialToken = aToken;
authorizedTokenKey = nil;
oauthBase = [base copy];
realm = [aRealm copy];
@@ -70,20 +70,6 @@ - (id)initWithConsumer:(OAConsumer *)aConsumer token:(OAToken *)aToken oauthBase
return self;
}
-- (void)dealloc {
- [consumer release];
- [acToken release];
- [reqToken release];
- [initialToken release];
- [authorizedTokenKey release];
- [oauthBase release];
- [realm release];
- [callback release];
- [calls release];
- [selectors release];
- [delegates release];
- [super dealloc];
-}
// The application got a new authorized
// request token and is notifying us
@@ -92,8 +78,7 @@ - (void)authorizedToken:(NSString *)aKey
if (reqToken && [aKey isEqualToString:reqToken.key]) {
[self exchangeToken];
} else {
- [authorizedTokenKey release];
- authorizedTokenKey = [aKey retain];
+ authorizedTokenKey = aKey;
}
}
@@ -148,10 +133,10 @@ - (void)callFinished:(OACall *)call body:(NSString *)body
SEL selector = [self getSelector:call];
id deleg = [delegates objectForKey:[NSString stringWithFormat:@"%p", call]];
if (deleg) {
- [deleg performSelector:selector withObject:body];
+ objc_msgSend(deleg, selector, body);
[delegates removeObjectForKey:call];
} else {
- [delegate performSelector:selector withObject:body];
+ objc_msgSend(delegate, selector, body);
}
@synchronized(self) {
isDispatching = NO;
@@ -175,7 +160,6 @@ - (void)enqueue:(OACall *)call selector:(SEL)selector {
if (idx == NSNotFound) {
@synchronized(calls) {
[calls addObject:call];
- [call release];
[selectors addObject:NSStringFromSelector(selector)];
}
}
@@ -212,18 +196,18 @@ - (SEL)getSelector:(OACall *)call
- (void)requestToken
{
/* Try to load an access token from settings */
- OAToken *atoken = [[[OAToken alloc] initWithUserDefaultsUsingServiceProviderName:oauthBase prefix:[@"access:" stringByAppendingString:realm]] autorelease];
+ OAToken *atoken = [[OAToken alloc] initWithUserDefaultsUsingServiceProviderName:oauthBase prefix:[@"access:" stringByAppendingString:realm]];
if (atoken && [atoken isValid]) {
[self setAccessToken:atoken];
return;
}
/* Try to load a stored requestToken from
settings (useful for iPhone) */
- OAToken *token = [[[OAToken alloc] initWithUserDefaultsUsingServiceProviderName:oauthBase prefix:[@"request:" stringByAppendingString:realm]] autorelease];
+ OAToken *token = [[OAToken alloc] initWithUserDefaultsUsingServiceProviderName:oauthBase prefix:[@"request:" stringByAppendingString:realm]];
/* iPhone specific, the manager must have got the authorized token before reaching this point */
NSLog(@"request token in settings %@", token);
if (token && token.key && [authorizedTokenKey isEqualToString:token.key]) {
- reqToken = [token retain];
+ reqToken = token;
[self exchangeToken];
return;
}
@@ -245,20 +229,21 @@ - (void)requestTokenReceived:(OACall *)call body:(NSString *)body
{
/* XXX: Check if token != nil */
NSLog(@"Received request token %@", body);
- OAToken *token = [[[OAToken alloc] initWithHTTPResponseBody:body] autorelease];
+ OAToken *token = [[OAToken alloc] initWithHTTPResponseBody:body];
if (token) {
- [reqToken release];
- reqToken = [token retain];
+ reqToken = token;
[reqToken storeInUserDefaultsWithServiceProviderName:oauthBase prefix:[@"request:" stringByAppendingString:realm]];
/* Save the token in case we exit and start again
before the token is authorized (useful for iPhone) */
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@authorize?oauth_token=%@&oauth_callback=%@",
oauthBase, token.key, callback]];
- [[UIApplication sharedApplication] openURL:url];
-
+ #if TARGET_OS_IPHONE
+ [[UIApplication sharedApplication] openURL:url];
+ #else
+ [[NSWorkspace sharedWorkspace] openURL: url];
+ #endif
}
- [call release];
}
// Exchaing a request token for an access token
@@ -282,7 +267,7 @@ - (void)exchangeToken
- (void)accessTokenReceived:(OACall *)call body:(NSString *)body
{
- OAToken *token = [[[OAToken alloc] initWithHTTPResponseBody:body] autorelease];
+ OAToken *token = [[OAToken alloc] initWithHTTPResponseBody:body];
[self setAccessToken:token];
}
@@ -307,8 +292,7 @@ - (void)setAccessToken:(OAToken *)token {
this access token */
[self deleteSavedRequestToken];
if (token) {
- [acToken release];
- acToken = [token retain];
+ acToken = token;
[acToken storeInUserDefaultsWithServiceProviderName:oauthBase prefix:[@"access:" stringByAppendingString:realm]];
@synchronized(self) {
isDispatching = NO;
@@ -316,7 +300,6 @@ - (void)setAccessToken:(OAToken *)token {
[self dispatch];
} else {
/* Clear the in-memory and saved access tokens */
- [acToken release];
acToken = nil;
[OAToken removeFromUserDefaultsWithServiceProviderName:oauthBase prefix:[@"access:" stringByAppendingString:realm]];
}
@@ -324,7 +307,6 @@ - (void)setAccessToken:(OAToken *)token {
- (void)deleteSavedRequestToken {
[OAToken removeFromUserDefaultsWithServiceProviderName:oauthBase prefix:[@"request:" stringByAppendingString:realm]];
- [reqToken release];
reqToken = nil;
}
@@ -361,10 +343,10 @@ - (void)dispatch {
- (void)fetchData:(NSString *)aURL method:(NSString *)aMethod parameters:(NSArray *)theParameters
files:(NSDictionary *)theFiles finished:(SEL)didFinish delegate:(NSObject*)aDelegate {
- OACall *call = [[[OACall alloc] initWithURL:[NSURL URLWithString:aURL]
+ OACall *call = [[OACall alloc] initWithURL:[NSURL URLWithString:aURL]
method:aMethod
parameters:theParameters
- files:theFiles] autorelease];
+ files:theFiles];
NSLog(@"Received request for: %@", aURL);
[self enqueue:call selector:didFinish];
if (aDelegate) {
View
0  OAuthConsumer.h 100644 → 100755
File mode changed
Something went wrong with that request. Please try again.