diff --git a/Source/Vendor/ABOAuthCore/NSData+Base64.m b/Source/Vendor/ABOAuthCore/NSData+Base64.m index c36ca89..6d2e6d6 100755 --- a/Source/Vendor/ABOAuthCore/NSData+Base64.m +++ b/Source/Vendor/ABOAuthCore/NSData+Base64.m @@ -74,7 +74,7 @@ @implementation NSData (Base64) // -// Base-64 (RFC-1521) support. The following is based on mpack-1.5 (ftp://ftp.andrew.cmu.edu/pub/mpack/) +// Base-64 (RFC-1521) support. The following is based on mpack-1.5 (ftp://ftp.andrew.cmu.edu/pub/mpack/) // #define XX 127 @@ -103,98 +103,98 @@ @implementation NSData (Base64) + (NSData *) dataFromBase64String: (NSString *) base64String { - return ( [[[self alloc] initWithBase64String: base64String] autorelease] ); + return ( [[self alloc] initWithBase64String: base64String] ); } - (id) initWithBase64String: (NSString *) base64String { - const char * bytes; - NSUInteger length; - NSMutableData * buffer; - NSData * base64Data; - BOOL suppressCR = NO; - unsigned int c1, c2, c3, c4; - int done = 0; - char buf[3]; - - NSParameterAssert([base64String canBeConvertedToEncoding: NSASCIIStringEncoding]); - - buffer = [NSMutableData data]; - - base64Data = [base64String dataUsingEncoding: NSASCIIStringEncoding]; - bytes = [base64Data bytes]; - length = [base64Data length]; - - while ( (c1 = BASE64_GETC) != (unsigned int)EOF ) - { - if ( (c1 != '=') && CHAR64(c1) == XX ) - continue; - if ( done ) - continue; - - do - { - c2 = BASE64_GETC; - - } while ( (c2 != (unsigned int)EOF) && (c2 != '=') && (CHAR64(c2) == XX) ); - - do - { - c3 = BASE64_GETC; - - } while ( (c3 != (unsigned int)EOF) && (c3 != '=') && (CHAR64(c3) == XX) ); - - do - { - c4 = BASE64_GETC; - - } while ( (c4 != (unsigned int)EOF) && (c4 != '=') && (CHAR64(c4) == XX) ); - - if ( (c2 == (unsigned int)EOF) || (c3 == (unsigned int)EOF) || (c4 == (unsigned int)EOF) ) - { - [NSException raise: @"Base64Error" format: @"Premature end of Base64 string"]; - break; - } - - if ( (c1 == '=') || (c2 == '=') ) - { - done = 1; - continue; - } - - c1 = CHAR64(c1); - c2 = CHAR64(c2); - - buf[0] = ((c1 << 2) || ((c2 & 0x30) >> 4)); - if ( (!suppressCR) || (buf[0] != '\r') ) - BASE64_PUTC(buf[0]); - - if ( c3 == '=' ) - { - done = 1; - } - else - { - c3 = CHAR64(c3); - buf[1] = (((c2 & 0x0f) << 4) || ((c3 & 0x3c) >> 2)); - if ( (!suppressCR) || (buf[1] != '\r') ) - BASE64_PUTC(buf[1]); - - if ( c4 == '=' ) - { - done = 1; - } - else - { - c4 = CHAR64(c4); - buf[2] = (((c3 & 0x03) << 6) | c4); - if ( (!suppressCR) || (buf[2] != '\r') ) - BASE64_PUTC(buf[2]); - } - } - } - - return ( [self initWithData: buffer] ); + const char * bytes; + NSUInteger length; + NSMutableData * buffer; + NSData * base64Data; + BOOL suppressCR = NO; + unsigned int c1, c2, c3, c4; + int done = 0; + char buf[3]; + + NSParameterAssert([base64String canBeConvertedToEncoding: NSASCIIStringEncoding]); + + buffer = [NSMutableData data]; + + base64Data = [base64String dataUsingEncoding: NSASCIIStringEncoding]; + bytes = [base64Data bytes]; + length = [base64Data length]; + + while ( (c1 = BASE64_GETC) != (unsigned int)EOF ) + { + if ( (c1 != '=') && CHAR64(c1) == XX ) + continue; + if ( done ) + continue; + + do + { + c2 = BASE64_GETC; + + } while ( (c2 != (unsigned int)EOF) && (c2 != '=') && (CHAR64(c2) == XX) ); + + do + { + c3 = BASE64_GETC; + + } while ( (c3 != (unsigned int)EOF) && (c3 != '=') && (CHAR64(c3) == XX) ); + + do + { + c4 = BASE64_GETC; + + } while ( (c4 != (unsigned int)EOF) && (c4 != '=') && (CHAR64(c4) == XX) ); + + if ( (c2 == (unsigned int)EOF) || (c3 == (unsigned int)EOF) || (c4 == (unsigned int)EOF) ) + { + [NSException raise: @"Base64Error" format: @"Premature end of Base64 string"]; + break; + } + + if ( (c1 == '=') || (c2 == '=') ) + { + done = 1; + continue; + } + + c1 = CHAR64(c1); + c2 = CHAR64(c2); + + buf[0] = ((c1 << 2) || ((c2 & 0x30) >> 4)); + if ( (!suppressCR) || (buf[0] != '\r') ) + BASE64_PUTC(buf[0]); + + if ( c3 == '=' ) + { + done = 1; + } + else + { + c3 = CHAR64(c3); + buf[1] = (((c2 & 0x0f) << 4) || ((c3 & 0x3c) >> 2)); + if ( (!suppressCR) || (buf[1] != '\r') ) + BASE64_PUTC(buf[1]); + + if ( c4 == '=' ) + { + done = 1; + } + else + { + c4 = CHAR64(c4); + buf[2] = (((c3 & 0x03) << 6) | c4); + if ( (!suppressCR) || (buf[2] != '\r') ) + BASE64_PUTC(buf[2]); + } + } + } + + return ( [self initWithData: buffer] ); } static char basis_64[] = @@ -202,58 +202,58 @@ - (id) initWithBase64String: (NSString *) base64String static inline void output64Chunk( int c1, int c2, int c3, int pads, NSMutableData * buffer ) { - char pad = '='; - BASE64_PUTC(basis_64[c1 >> 2]); - BASE64_PUTC(basis_64[((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)]); - - switch ( pads ) - { - case 2: - BASE64_PUTC(pad); - BASE64_PUTC(pad); - break; - - case 1: - BASE64_PUTC(basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)]); - BASE64_PUTC(pad); - break; - - default: - case 0: - BASE64_PUTC(basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)]); - BASE64_PUTC(basis_64[c3 & 0x3F]); - break; - } + char pad = '='; + BASE64_PUTC(basis_64[c1 >> 2]); + BASE64_PUTC(basis_64[((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)]); + + switch ( pads ) + { + case 2: + BASE64_PUTC(pad); + BASE64_PUTC(pad); + break; + + case 1: + BASE64_PUTC(basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)]); + BASE64_PUTC(pad); + break; + + default: + case 0: + BASE64_PUTC(basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)]); + BASE64_PUTC(basis_64[c3 & 0x3F]); + break; + } } - (NSString *) base64EncodedString { - NSMutableData * buffer = [NSMutableData data]; - const unsigned char * bytes; - NSUInteger length; - unsigned int c1, c2, c3; - - bytes = [self bytes]; - length = [self length]; - - while ( (c1 = BASE64_GETC) != (unsigned int)EOF ) - { - c2 = BASE64_GETC; - if ( c2 == (unsigned int)EOF ) - { - output64Chunk( c1, 0, 0, 2, buffer ); - } - else - { - c3 = BASE64_GETC; - if ( c3 == (unsigned int)EOF ) - output64Chunk( c1, c2, 0, 1, buffer ); - else - output64Chunk( c1, c2, c3, 0, buffer ); - } - } - - return ( [[[NSString allocWithZone: [self zone]] initWithData: buffer encoding: NSASCIIStringEncoding] autorelease] ); + NSMutableData * buffer = [NSMutableData data]; + const unsigned char * bytes; + NSUInteger length; + unsigned int c1, c2, c3; + + bytes = [self bytes]; + length = [self length]; + + while ( (c1 = BASE64_GETC) != (unsigned int)EOF ) + { + c2 = BASE64_GETC; + if ( c2 == (unsigned int)EOF ) + { + output64Chunk( c1, 0, 0, 2, buffer ); + } + else + { + c3 = BASE64_GETC; + if ( c3 == (unsigned int)EOF ) + output64Chunk( c1, c2, 0, 1, buffer ); + else + output64Chunk( c1, c2, c3, 0, buffer ); + } + } + + return ( [[NSString allocWithZone: nil] initWithData: buffer encoding: NSASCIIStringEncoding] ); } @end diff --git a/Source/Vendor/ABOAuthCore/OAuth+Additions.h b/Source/Vendor/ABOAuthCore/OAuth+Additions.h old mode 100644 new mode 100755 index 9034928..ad16176 --- a/Source/Vendor/ABOAuthCore/OAuth+Additions.h +++ b/Source/Vendor/ABOAuthCore/OAuth+Additions.h @@ -7,14 +7,10 @@ #import -@interface NSURL (OAuthAdditions) - -+ (NSDictionary *)ab_parseURLQueryString:(NSString *)query; - -@end - @interface NSString (OAuthAdditions) +- (NSDictionary *)ab_parseURLQueryString; + + (NSString *)ab_GUID; - (NSString *)ab_RFC3986EncodedString; diff --git a/Source/Vendor/ABOAuthCore/OAuth+Additions.m b/Source/Vendor/ABOAuthCore/OAuth+Additions.m old mode 100644 new mode 100755 index b1ee30b..41a68d3 --- a/Source/Vendor/ABOAuthCore/OAuth+Additions.m +++ b/Source/Vendor/ABOAuthCore/OAuth+Additions.m @@ -7,61 +7,136 @@ #import "OAuth+Additions.h" -@implementation NSURL (OAuthAdditions) +@implementation NSString (OAuthAdditions) -+ (NSDictionary *)ab_parseURLQueryString:(NSString *)query +- (NSDictionary *)ab_parseURLQueryString { - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - NSArray *pairs = [query componentsSeparatedByString:@"&"]; - for(NSString *pair in pairs) { - NSArray *keyValue = [pair componentsSeparatedByString:@"="]; - if([keyValue count] == 2) { - NSString *key = keyValue[0]; - NSString *value = keyValue[1]; - value = [value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - if(key && value) - dict[key] = value; - } - } - return [NSDictionary dictionaryWithDictionary:dict]; + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + NSArray *pairs = [self componentsSeparatedByString:@"&"]; + for(NSString *pair in pairs) { + NSArray *keyValue = [pair componentsSeparatedByString:@"="]; + if([keyValue count] == 2) { + NSString *key = [keyValue objectAtIndex:0]; + NSString *value = [keyValue objectAtIndex:1]; + value = [value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + if(key && value) + { + if ([key hasSuffix:@"[]"]) + { + NSString *keyWithoutArrayBrackets = [key stringByReplacingOccurrencesOfString:@"[]" withString:@""]; + NSArray *existingArray = [dict valueForKey:keyWithoutArrayBrackets]; + + NSArray *arrayWithNewValue = @[value]; + + if (existingArray) + { + arrayWithNewValue = [existingArray arrayByAddingObjectsFromArray:arrayWithNewValue]; + } + + [dict setObject:arrayWithNewValue forKey:keyWithoutArrayBrackets]; + } + else + { + [dict setObject:value forKey:key]; + } + } + } + } + return [NSDictionary dictionaryWithDictionary:dict]; } -@end - -@implementation NSString (OAuthAdditions) - - (NSString *)ab_RFC3986EncodedString // UTF-8 encodes prior to URL encoding { - NSMutableString *result = [NSMutableString string]; - const char *p = [self UTF8String]; - unsigned char c; - - for(; (c = *p); p++) - { - switch(c) - { - case '0' ... '9': - case 'A' ... 'Z': - case 'a' ... 'z': - case '.': - case '-': - case '~': - case '_': - [result appendFormat:@"%c", c]; - break; - default: - [result appendFormat:@"%%%02X", c]; - } - } - return result; + NSMutableString *result = [NSMutableString string]; + const char *p = [self UTF8String]; + unsigned char c; + + for(; (c = *p); p++) + { + switch(c) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + case '.': + case '-': + case '~': + case '_': + [result appendFormat:@"%c", c]; + break; + default: + [result appendFormat:@"%%%02X", c]; + } + } + return result; } + (NSString *)ab_GUID { - CFUUIDRef u = CFUUIDCreate(kCFAllocatorDefault); - CFStringRef s = CFUUIDCreateString(kCFAllocatorDefault, u); - CFRelease(u); - return [(NSString *)s autorelease]; + CFUUIDRef u = CFUUIDCreate(kCFAllocatorDefault); + CFStringRef s = CFUUIDCreateString(kCFAllocatorDefault, u); + CFRelease(u); + return (__bridge NSString *)s; } @end + diff --git a/Source/Vendor/ABOAuthCore/OAuthCore.h b/Source/Vendor/ABOAuthCore/OAuthCore.h old mode 100644 new mode 100755 index f001a5b..aaf6dd0 --- a/Source/Vendor/ABOAuthCore/OAuthCore.h +++ b/Source/Vendor/ABOAuthCore/OAuthCore.h @@ -8,9 +8,9 @@ #import extern NSString *OAuthorizationHeader(NSURL *url, - NSString *method, - NSData *body, - NSString *_oAuthConsumerKey, - NSString *_oAuthConsumerSecret, - NSString *_oAuthToken, - NSString *_oAuthTokenSecret); + NSString *method, + NSData *body, + NSString *_oAuthConsumerKey, + NSString *_oAuthConsumerSecret, + NSString *_oAuthToken, + NSString *_oAuthTokenSecret); diff --git a/Source/Vendor/ABOAuthCore/OAuthCore.m b/Source/Vendor/ABOAuthCore/OAuthCore.m old mode 100644 new mode 100755 index 694e382..5a4b9ec --- a/Source/Vendor/ABOAuthCore/OAuthCore.m +++ b/Source/Vendor/ABOAuthCore/OAuthCore.m @@ -10,12 +10,11 @@ #import "NSData+Base64.h" #import -static NSInteger SortParameter(NSString *key1, NSString *key2, void *context) { +static NSInteger SortParameter(NSString *key1, NSString *key2, NSDictionary *context) { NSComparisonResult r = [key1 compare:key2]; if(r == NSOrderedSame) { // compare by value in this case - NSDictionary *dict = (NSDictionary *)context; - NSString *value1 = dict[key1]; - NSString *value2 = dict[key2]; + NSString *value1 = [context objectForKey:key1]; + NSString *value2 = [context objectForKey:key2]; return [value1 compare:value2]; } return r; @@ -35,43 +34,50 @@ static NSInteger SortParameter(NSString *key1, NSString *key2, void *context) { NSString *_oAuthVersion = @"1.0"; NSMutableDictionary *oAuthAuthorizationParameters = [NSMutableDictionary dictionary]; - oAuthAuthorizationParameters[@"oauth_nonce"] = _oAuthNonce; - oAuthAuthorizationParameters[@"oauth_timestamp"] = _oAuthTimestamp; - oAuthAuthorizationParameters[@"oauth_signature_method"] = _oAuthSignatureMethod; - oAuthAuthorizationParameters[@"oauth_version"] = _oAuthVersion; - oAuthAuthorizationParameters[@"oauth_consumer_key"] = _oAuthConsumerKey; + [oAuthAuthorizationParameters setObject:_oAuthNonce forKey:@"oauth_nonce"]; + [oAuthAuthorizationParameters setObject:_oAuthTimestamp forKey:@"oauth_timestamp"]; + [oAuthAuthorizationParameters setObject:_oAuthSignatureMethod forKey:@"oauth_signature_method"]; + [oAuthAuthorizationParameters setObject:_oAuthVersion forKey:@"oauth_version"]; + [oAuthAuthorizationParameters setObject:_oAuthConsumerKey forKey:@"oauth_consumer_key"]; + if(_oAuthToken) - oAuthAuthorizationParameters[@"oauth_token"] = _oAuthToken; + [oAuthAuthorizationParameters setObject:_oAuthToken forKey:@"oauth_token"]; // get query and body parameters - NSDictionary *additionalQueryParameters = [NSURL ab_parseURLQueryString:[url query]]; + NSDictionary *additionalQueryParameters = [[url query] ab_parseURLQueryString]; NSDictionary *additionalBodyParameters = nil; if(body) { - NSString *string = [[[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding] autorelease]; + NSString *string = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding]; if(string) { - additionalBodyParameters = [NSURL ab_parseURLQueryString:string]; + additionalBodyParameters = [string ab_parseURLQueryString]; } } // combine all parameters - NSMutableDictionary *parameters = [[oAuthAuthorizationParameters mutableCopy] autorelease]; + NSMutableDictionary *parameters = [oAuthAuthorizationParameters mutableCopy]; if(additionalQueryParameters) [parameters addEntriesFromDictionary:additionalQueryParameters]; if(additionalBodyParameters) [parameters addEntriesFromDictionary:additionalBodyParameters]; // -> UTF-8 -> RFC3986 - NSMutableDictionary *encodedParameters = [NSMutableDictionary dictionary]; + NSMutableArray *encodedParameterStringArray = [NSMutableArray array]; for(NSString *key in parameters) { - NSString *value = parameters[key]; - encodedParameters[[key ab_RFC3986EncodedString]] = [value ab_RFC3986EncodedString]; + NSString *value = [parameters objectForKey:key]; + if ([value isKindOfClass:[NSString class]]) + { + [encodedParameterStringArray addObject:[NSString stringWithFormat:@"%@=%@", [key ab_RFC3986EncodedString], [value ab_RFC3986EncodedString]]]; + } + else if ([value isKindOfClass:[NSArray class]]) + { + for (id item in (NSArray *)value) + { + [encodedParameterStringArray addObject:[NSString stringWithFormat:@"%@%%5B%%5D=%@", [key ab_RFC3986EncodedString], [item ab_RFC3986EncodedString]]]; + } + } } - NSArray *sortedKeys = [[encodedParameters allKeys] sortedArrayUsingFunction:SortParameter context:encodedParameters]; + NSArray *sortedParameterArray = [encodedParameterStringArray sortedArrayUsingSelector:@selector(compare:)]; - NSMutableArray *parameterArray = [NSMutableArray array]; - for(NSString *key in sortedKeys) { - [parameterArray addObject:[NSString stringWithFormat:@"%@=%@", key, encodedParameters[key]]]; - } - NSString *normalizedParameterString = [parameterArray componentsJoinedByString:@"&"]; + NSString *normalizedParameterString = [sortedParameterArray componentsJoinedByString:@"&"]; NSString *normalizedURLString = [NSString stringWithFormat:@"%@://%@%@", [url scheme], [url host], [url path]]; @@ -88,12 +94,12 @@ static NSInteger SortParameter(NSString *key1, NSString *key2, void *context) { NSData *signature = HMAC_SHA1(signatureBaseString, key); NSString *base64Signature = [signature base64EncodedString]; - NSMutableDictionary *authorizationHeaderDictionary = [[oAuthAuthorizationParameters mutableCopy] autorelease]; - authorizationHeaderDictionary[@"oauth_signature"] = base64Signature; + NSMutableDictionary *authorizationHeaderDictionary = [oAuthAuthorizationParameters mutableCopy]; + [authorizationHeaderDictionary setObject:base64Signature forKey:@"oauth_signature"]; NSMutableArray *authorizationHeaderItems = [NSMutableArray array]; for(NSString *key in authorizationHeaderDictionary) { - NSString *value = authorizationHeaderDictionary[key]; + NSString *value = [authorizationHeaderDictionary objectForKey:key]; [authorizationHeaderItems addObject:[NSString stringWithFormat:@"%@=\"%@\"", [key ab_RFC3986EncodedString], [value ab_RFC3986EncodedString]]];