Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc

# Logs and databases #
######################
*.log

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
34 changes: 17 additions & 17 deletions Source/Framework/Crypto/Base64Transcoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@
#include <string.h>

const u_int8_t kBase64EncodeTable[64] = {
/* 0 */ 'A', /* 1 */ 'B', /* 2 */ 'C', /* 3 */ 'D',
/* 4 */ 'E', /* 5 */ 'F', /* 6 */ 'G', /* 7 */ 'H',
/* 8 */ 'I', /* 9 */ 'J', /* 10 */ 'K', /* 11 */ 'L',
/* 12 */ 'M', /* 13 */ 'N', /* 14 */ 'O', /* 15 */ 'P',
/* 16 */ 'Q', /* 17 */ 'R', /* 18 */ 'S', /* 19 */ 'T',
/* 20 */ 'U', /* 21 */ 'V', /* 22 */ 'W', /* 23 */ 'X',
/* 24 */ 'Y', /* 25 */ 'Z', /* 26 */ 'a', /* 27 */ 'b',
/* 28 */ 'c', /* 29 */ 'd', /* 30 */ 'e', /* 31 */ 'f',
/* 32 */ 'g', /* 33 */ 'h', /* 34 */ 'i', /* 35 */ 'j',
/* 36 */ 'k', /* 37 */ 'l', /* 38 */ 'm', /* 39 */ 'n',
/* 40 */ 'o', /* 41 */ 'p', /* 42 */ 'q', /* 43 */ 'r',
/* 44 */ 's', /* 45 */ 't', /* 46 */ 'u', /* 47 */ 'v',
/* 48 */ 'w', /* 49 */ 'x', /* 50 */ 'y', /* 51 */ 'z',
/* 52 */ '0', /* 53 */ '1', /* 54 */ '2', /* 55 */ '3',
/* 56 */ '4', /* 57 */ '5', /* 58 */ '6', /* 59 */ '7',
/* 0 */ 'A', /* 1 */ 'B', /* 2 */ 'C', /* 3 */ 'D',
/* 4 */ 'E', /* 5 */ 'F', /* 6 */ 'G', /* 7 */ 'H',
/* 8 */ 'I', /* 9 */ 'J', /* 10 */ 'K', /* 11 */ 'L',
/* 12 */ 'M', /* 13 */ 'N', /* 14 */ 'O', /* 15 */ 'P',
/* 16 */ 'Q', /* 17 */ 'R', /* 18 */ 'S', /* 19 */ 'T',
/* 20 */ 'U', /* 21 */ 'V', /* 22 */ 'W', /* 23 */ 'X',
/* 24 */ 'Y', /* 25 */ 'Z', /* 26 */ 'a', /* 27 */ 'b',
/* 28 */ 'c', /* 29 */ 'd', /* 30 */ 'e', /* 31 */ 'f',
/* 32 */ 'g', /* 33 */ 'h', /* 34 */ 'i', /* 35 */ 'j',
/* 36 */ 'k', /* 37 */ 'l', /* 38 */ 'm', /* 39 */ 'n',
/* 40 */ 'o', /* 41 */ 'p', /* 42 */ 'q', /* 43 */ 'r',
/* 44 */ 's', /* 45 */ 't', /* 46 */ 'u', /* 47 */ 'v',
/* 48 */ 'w', /* 49 */ 'x', /* 50 */ 'y', /* 51 */ 'z',
/* 52 */ '0', /* 53 */ '1', /* 54 */ '2', /* 55 */ '3',
/* 56 */ '4', /* 57 */ '5', /* 58 */ '6', /* 59 */ '7',
/* 60 */ '8', /* 61 */ '9', /* 62 */ '+', /* 63 */ '/'
};

/*
-1 = Base64 end of data marker.
-2 = White space (tabs, cr, lf, space)
-3 = Noise (all non whitespace, non-base64 characters)
-3 = Noise (all non whitespace, non-base64 characters)
-4 = Dangerous noise
-5 = Illegal noise (null byte)
*/
Expand Down Expand Up @@ -179,7 +179,7 @@ size_t theSequence = 0;
for (; theInIndex < inInputDataSize; )
{
int8_t theSextet = 0;

int8_t theCurrentInputOctet = theInPtr[theInIndex];
theSextet = kBase64DecodeTable[theCurrentInputOctet];
if (theSextet == -1)
Expand Down
44 changes: 22 additions & 22 deletions Source/Framework/MPOAuthAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ - (id)initWithCredentials:(NSDictionary *)inCredentials andBaseURL:(NSURL *)inBa
}

- (id)initWithCredentials:(NSDictionary *)inCredentials authenticationURL:(NSURL *)inAuthURL andBaseURL:(NSURL *)inBaseURL {
return [self initWithCredentials:inCredentials authenticationURL:inBaseURL andBaseURL:inBaseURL autoStart:YES];
return [self initWithCredentials:inCredentials authenticationURL:inBaseURL andBaseURL:inBaseURL autoStart:YES];
}

- (id)initWithCredentials:(NSDictionary *)inCredentials authenticationURL:(NSURL *)inAuthURL andBaseURL:(NSURL *)inBaseURL autoStart:(BOOL)aFlag {
Expand All @@ -62,12 +62,12 @@ - (id)initWithCredentials:(NSDictionary *)inCredentials authenticationURL:(NSURL
self.signatureScheme = MPOAuthSignatureSchemeHMACSHA1;

activeLoaders_ = [[NSMutableArray alloc] initWithCapacity:10];

if (aFlag) {
[self authenticate];
}
}
return self;
return self;
}

- (id)initWithCredentials:(NSDictionary *)inCredentials withConfiguration:(NSDictionary *)inConfiguration autoStart:(BOOL)aFlag {
Expand All @@ -76,16 +76,16 @@ - (id)initWithCredentials:(NSDictionary *)inCredentials withConfiguration:(NSDic
self.baseURL = [inConfiguration valueForKey:MPOAuthBaseURLKey];
self.authenticationState = MPOAuthAuthenticationStateUnauthenticated;
credentials_ = [[MPOAuthCredentialConcreteStore alloc] initWithCredentials:inCredentials forBaseURL:self.baseURL withAuthenticationURL:self.authenticationURL];
self.authenticationMethod = [[MPOAuthAuthenticationMethod alloc] initWithAPI:self forURL:self.authenticationURL withConfiguration:inConfiguration];
self.authenticationMethod = [[MPOAuthAuthenticationMethod alloc] initWithAPI:self forURL:self.authenticationURL withConfiguration:inConfiguration];
self.signatureScheme = MPOAuthSignatureSchemeHMACSHA1;

activeLoaders_ = [[NSMutableArray alloc] initWithCapacity:10];

if (aFlag) {
[self authenticate];
}
}
return self;
return self;
}

- (oneway void)dealloc {
Expand All @@ -94,7 +94,7 @@ - (oneway void)dealloc {
self.authenticationURL = nil;
self.authenticationMethod = nil;
self.activeLoaders = nil;

[super dealloc];
}

Expand All @@ -110,9 +110,9 @@ - (oneway void)dealloc {

- (void)setSignatureScheme:(MPOAuthSignatureScheme)inScheme {
signatureScheme_ = inScheme;

NSString *methodString = @"HMAC-SHA1";

switch (signatureScheme_) {
case MPOAuthSignatureSchemePlainText:
methodString = @"PLAINTEXT";
Expand All @@ -124,7 +124,7 @@ - (void)setSignatureScheme:(MPOAuthSignatureScheme)inScheme {
// already initted to the default
break;
}

[(MPOAuthCredentialConcreteStore *)credentials_ setSignatureMethod:methodString];
}

Expand Down Expand Up @@ -165,19 +165,19 @@ - (void)performMethod:(NSString *)inMethod atURL:(NSURL *)inURL withParameters:(
if (!inMethod && ![inURL path] && ![inURL query]) {
[NSException raise:@"MPOAuthNilMethodRequestException" format:@"Nil was passed as the method to be performed on %@", inURL];
}

NSURL *requestURL = inMethod ? [NSURL URLWithString:inMethod relativeToURL:inURL] : inURL;
MPOAuthURLRequest *aRequest = [[MPOAuthURLRequest alloc] initWithURL:requestURL andParameters:inParameters];
MPOAuthAPIRequestLoader *loader = [[MPOAuthAPIRequestLoader alloc] initWithRequest:aRequest];

aRequest.HTTPMethod = inHTTPMethod;
loader.credentials = self.credentials;
loader.target = inTarget;
loader.action = inAction ? inAction : @selector(_performedLoad:receivingData:);

[loader loadSynchronously:NO];
// [self.activeLoaders addObject:loader];

[loader release];
[aRequest release];
}
Expand All @@ -189,16 +189,16 @@ - (void)performURLRequest:(NSURLRequest *)inRequest withTarget:(id)inTarget andA

MPOAuthURLRequest *aRequest = [[MPOAuthURLRequest alloc] initWithURLRequest:inRequest];
MPOAuthAPIRequestLoader *loader = [[MPOAuthAPIRequestLoader alloc] initWithRequest:aRequest];

loader.credentials = self.credentials;
loader.target = inTarget;
loader.action = inAction ? inAction : @selector(_performedLoad:receivingData:);

[loader loadSynchronously:NO];
// [self.activeLoaders addObject:loader];

[loader release];
[aRequest release];
[aRequest release];
}

- (NSData *)dataForMethod:(NSString *)inMethod {
Expand All @@ -216,10 +216,10 @@ - (NSData *)dataForURL:(NSURL *)inURL andMethod:(NSString *)inMethod withParamet

loader.credentials = self.credentials;
[loader loadSynchronously:YES];

[loader autorelease];
[aRequest release];

return loader.data;
}

Expand All @@ -239,7 +239,7 @@ - (void)removeCredentialNamed:(NSString *)inName {

- (void)discardCredentials {
[self.credentials discardOAuthCredentials];

self.authenticationState = MPOAuthAuthenticationStateUnauthenticated;
}

Expand Down
32 changes: 16 additions & 16 deletions Source/Framework/MPOAuthAPIRequestLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ - (MPOAuthURLResponse *)oauthResponse {
if (!_oauthResponse) {
_oauthResponse = [[MPOAuthURLResponse alloc] init];
}

return _oauthResponse;
}

- (NSString *)responseString {
if (!_dataAsString) {
_dataAsString = [[NSString alloc] initWithData:self.data encoding:[self.oauthResponse.urlResponse encoding]];
}

return _dataAsString;
}

- (void)loadSynchronously:(BOOL)inSynchronous {
NSAssert(_credentials, @"Unable to load without valid credentials");
NSAssert(_credentials.consumerKey, @"Unable to load, credentials contain no consumer key");

if (!inSynchronous) {
[MPOAuthConnection connectionWithRequest:self.oauthRequest delegate:self credentials:self.credentials];
} else {
Expand Down Expand Up @@ -131,7 +131,7 @@ - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSUR

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self _interrogateResponseForOAuthData];

if (_action) {
if ([_target conformsToProtocol:@protocol(MPOAuthAPIInternalClient)]) {
[_target performSelector:_action withObject:self withObject:self.data];
Expand All @@ -147,21 +147,21 @@ - (void)_interrogateResponseForOAuthData {
NSString *response = self.responseString;
NSDictionary *foundParameters = nil;
NSInteger status = [(NSHTTPURLResponse *)[self.oauthResponse urlResponse] statusCode];

if ([response length] > 5 && [[response substringToIndex:5] isEqualToString:@"oauth"]) {
foundParameters = [MPURLRequestParameter parameterDictionaryFromString:response];
self.oauthResponse.oauthParameters = foundParameters;

if (status == 401 || [foundParameters objectForKey:@"oauth_problem"]) {
NSString *aParameterValue = nil;
MPLog(@"oauthProblem = %@", foundParameters);

if ([foundParameters count] && (aParameterValue = [foundParameters objectForKey:@"oauth_problem"])) {
if ([aParameterValue isEqualToString:@"token_rejected"]) {
if (self.credentials.requestToken && !self.credentials.accessToken) {
[_credentials setRequestToken:nil];
[_credentials setRequestTokenSecret:nil];

[[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationRequestTokenRejected
object:nil
userInfo:foundParameters];
Expand All @@ -171,10 +171,10 @@ - (void)_interrogateResponseForOAuthData {
[[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationAccessTokenRejected
object:nil
userInfo:foundParameters];
}

}
}

// something's messed up, so throw an error
[[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationErrorHasOccurred
object:nil
Expand All @@ -188,26 +188,26 @@ - (void)_interrogateResponseForOAuthData {
if (!self.credentials.requestToken && !self.credentials.accessToken) {
[_credentials setRequestToken:aParameterValue];
[_credentials setRequestTokenSecret:[foundParameters objectForKey:@"oauth_token_secret"]];

[[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationRequestTokenReceived
object:nil
userInfo:foundParameters];

} else if (!self.credentials.accessToken && self.credentials.requestToken) {
[_credentials setRequestToken:nil];
[_credentials setRequestTokenSecret:nil];
[_credentials setAccessToken:aParameterValue];
[_credentials setAccessTokenSecret:[foundParameters objectForKey:@"oauth_token_secret"]];

[[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationAccessTokenReceived
object:nil
userInfo:foundParameters];

} else if (self.credentials.accessToken && !self.credentials.requestToken) {
// replace the current token
[_credentials setAccessToken:aParameterValue];
[_credentials setAccessTokenSecret:[foundParameters objectForKey:@"oauth_token_secret"]];

[[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationAccessTokenRefreshed
object:nil
userInfo:foundParameters];
Expand Down
Loading