├── .gitignore ├── Demo ├── Default-568h@2x.png ├── OAuthTwitterDemo.xcodeproj │ └── project.pbxproj ├── Rsc │ ├── MainWindow.xib │ ├── OAuthTwitterDemo-Info.plist │ └── OAuthTwitterDemoViewController.xib └── Src │ ├── OAuthTwitterDemoAppDelegate.h │ ├── OAuthTwitterDemoAppDelegate.m │ ├── OAuthTwitterDemoViewController.h │ ├── OAuthTwitterDemoViewController.m │ ├── OAuthTwitterDemo_Prefix.pch │ └── main.m ├── OAuthConsumeriPhoneLib ├── .gitignore ├── BuildCombined.sh ├── OAuthConsumer-iPhoneLib.xcodeproj │ └── project.pbxproj ├── OAuthConsumerSrc │ ├── Crypto │ │ ├── Base64Transcoder.c │ │ ├── Base64Transcoder.h │ │ ├── hmac.c │ │ ├── hmac.h │ │ ├── sha1.c │ │ └── sha1.h │ ├── NSMutableURLRequest+Parameters.h │ ├── NSMutableURLRequest+Parameters.m │ ├── NSString+URLEncoding.h │ ├── NSString+URLEncoding.m │ ├── NSURL+Base.h │ ├── NSURL+Base.m │ ├── OAAsynchronousDataFetcher.h │ ├── OAAsynchronousDataFetcher.m │ ├── OAConsumer.h │ ├── OAConsumer.m │ ├── OADataFetcher.h │ ├── OADataFetcher.m │ ├── OAHMAC_SHA1SignatureProvider.h │ ├── OAHMAC_SHA1SignatureProvider.m │ ├── OAMutableURLRequest.h │ ├── OAMutableURLRequest.m │ ├── OAPlaintextSignatureProvider.h │ ├── OAPlaintextSignatureProvider.m │ ├── OARequestParameter.h │ ├── OARequestParameter.m │ ├── OAServiceTicket.h │ ├── OAServiceTicket.m │ ├── OASignatureProviding.h │ ├── OAToken.h │ ├── OAToken.m │ ├── OAToken_KeychainExtensions.h │ ├── OAToken_KeychainExtensions.m │ └── OAuthConsumer.h ├── OAuthConsumer_iPhone_Prefix.pch └── ReadMe.txt ├── ReadMe.txt └── Twitter+OAuth ├── Libraries & Headers ├── OAuthConsumer │ ├── NSMutableURLRequest+Parameters.h │ ├── NSString+URLEncoding.h │ ├── NSURL+Base.h │ ├── OAAsynchronousDataFetcher.h │ ├── OAConsumer.h │ ├── OADataFetcher.h │ ├── OAHMAC_SHA1SignatureProvider.h │ ├── OAMutableURLRequest.h │ ├── OAPlaintextSignatureProvider.h │ ├── OARequestParameter.h │ ├── OAServiceTicket.h │ ├── OASignatureProviding.h │ ├── OAToken.h │ ├── OAToken_KeychainExtensions.h │ └── OAuthConsumer.h ├── jQueryInject.txt ├── jQueryInjectLandscape.txt └── libOAuth.a ├── MGTwitterEngine ├── MGTwitterEngine.h ├── MGTwitterEngine.m ├── MGTwitterEngineDelegate.h ├── MGTwitterEngineGlobalHeader.h ├── MGTwitterHTTPURLConnection.h ├── MGTwitterHTTPURLConnection.m ├── MGTwitterLibXMLParser.h ├── MGTwitterLibXMLParser.m ├── MGTwitterMessagesLibXMLParser.h ├── MGTwitterMessagesLibXMLParser.m ├── MGTwitterMessagesParser.h ├── MGTwitterMessagesParser.m ├── MGTwitterMiscLibXMLParser.h ├── MGTwitterMiscLibXMLParser.m ├── MGTwitterMiscParser.h ├── MGTwitterMiscParser.m ├── MGTwitterParserDelegate.h ├── MGTwitterRequestTypes.h ├── MGTwitterStatusesLibXMLParser.h ├── MGTwitterStatusesLibXMLParser.m ├── MGTwitterStatusesParser.h ├── MGTwitterStatusesParser.m ├── MGTwitterUsersLibXMLParser.h ├── MGTwitterUsersLibXMLParser.m ├── MGTwitterUsersParser.h ├── MGTwitterUsersParser.m ├── MGTwitterXMLParser.h ├── MGTwitterXMLParser.m ├── NSData+Base64.h ├── NSData+Base64.m ├── NSString+UUID.h └── NSString+UUID.m └── SAOAuthTwitterEngine ├── SA_OAuthTwitterController.h ├── SA_OAuthTwitterController.m ├── SA_OAuthTwitterEngine.h ├── SA_OAuthTwitterEngine.m └── twitter_load.png /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | /Twitter+OAuth/Libraries & Headers/OAuthConsumer/.svn/ 4 | /OAuthConsumeriPhoneLib/OAuthConsumer-iPhoneLib.xcodeproj/xcuserdata/ 5 | /OAuthConsumeriPhoneLib/OAuthConsumer-iPhoneLib.xcodeproj/project.xcworkspace/ 6 | /Demo/OAuthTwitterDemo.xcodeproj/xcuserdata/ 7 | /Demo/OAuthTwitterDemo.xcodeproj/project.xcworkspace/ 8 | /Demo/build/ -------------------------------------------------------------------------------- /Demo/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bengottlieb/Twitter-OAuth-iPhone/1e8d95c4e6f3f99352574b2448aa8c160ec9a323/Demo/Default-568h@2x.png -------------------------------------------------------------------------------- /Demo/Rsc/MainWindow.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 768 5 | 10A288 6 | 715 7 | 1010 8 | 411.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 46 12 | 13 | 14 | YES 15 | 16 | 17 | 18 | YES 19 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 20 | 21 | 22 | YES 23 | 24 | YES 25 | 26 | 27 | YES 28 | 29 | 30 | 31 | YES 32 | 33 | IBFilesOwner 34 | 35 | 36 | IBFirstResponder 37 | 38 | 39 | 40 | OAuthTwitterDemoViewController 41 | 42 | 43 | 44 | 45 | 292 46 | {320, 480} 47 | 48 | 1 49 | MSAxIDEAA 50 | 51 | NO 52 | NO 53 | 54 | 55 | 56 | 57 | 58 | YES 59 | 60 | 61 | delegate 62 | 63 | 64 | 65 | 4 66 | 67 | 68 | 69 | viewController 70 | 71 | 72 | 73 | 11 74 | 75 | 76 | 77 | window 78 | 79 | 80 | 81 | 14 82 | 83 | 84 | 85 | 86 | YES 87 | 88 | 0 89 | 90 | 91 | 92 | 93 | 94 | -1 95 | 96 | 97 | File's Owner 98 | 99 | 100 | 3 101 | 102 | 103 | OAuthTwitterDemo App Delegate 104 | 105 | 106 | -2 107 | 108 | 109 | 110 | 111 | 10 112 | 113 | 114 | 115 | 116 | 12 117 | 118 | 119 | 120 | 121 | 122 | 123 | YES 124 | 125 | YES 126 | -1.CustomClassName 127 | -2.CustomClassName 128 | 10.CustomClassName 129 | 10.IBEditorWindowLastContentRect 130 | 10.IBPluginDependency 131 | 12.IBEditorWindowLastContentRect 132 | 12.IBPluginDependency 133 | 3.CustomClassName 134 | 3.IBPluginDependency 135 | 136 | 137 | YES 138 | UIApplication 139 | UIResponder 140 | OAuthTwitterDemoViewController 141 | {{512, 351}, {320, 480}} 142 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 143 | {{525, 346}, {320, 480}} 144 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 145 | OAuthTwitterDemoAppDelegate 146 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 147 | 148 | 149 | 150 | YES 151 | 152 | 153 | YES 154 | 155 | 156 | 157 | 158 | YES 159 | 160 | 161 | YES 162 | 163 | 164 | 165 | 14 166 | 167 | 168 | 169 | YES 170 | 171 | OAuthTwitterDemoAppDelegate 172 | NSObject 173 | 174 | YES 175 | 176 | YES 177 | viewController 178 | window 179 | 180 | 181 | YES 182 | OAuthTwitterDemoViewController 183 | UIWindow 184 | 185 | 186 | 187 | IBProjectSource 188 | Classes/OAuthTwitterDemoAppDelegate.h 189 | 190 | 191 | 192 | OAuthTwitterDemoAppDelegate 193 | NSObject 194 | 195 | IBUserSource 196 | 197 | 198 | 199 | 200 | OAuthTwitterDemoViewController 201 | UIViewController 202 | 203 | IBProjectSource 204 | Classes/OAuthTwitterDemoViewController.h 205 | 206 | 207 | 208 | 209 | 0 210 | 211 | com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 212 | 213 | 214 | YES 215 | OAuthTwitterDemo.xcodeproj 216 | 3 217 | 218 | 219 | -------------------------------------------------------------------------------- /Demo/Rsc/OAuthTwitterDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.standalone.twitteroauthtest 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /Demo/Src/OAuthTwitterDemoAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAuthTwitterDemoAppDelegate.h 3 | // OAuthTwitterDemo 4 | // 5 | // Created by Ben Gottlieb on 7/24/09. 6 | // Copyright Stand Alone, Inc. 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class OAuthTwitterDemoViewController; 12 | 13 | @interface OAuthTwitterDemoAppDelegate : NSObject { 14 | UIWindow *window; 15 | OAuthTwitterDemoViewController *viewController; 16 | } 17 | 18 | @property (nonatomic, retain) IBOutlet UIWindow *window; 19 | @property (nonatomic, retain) IBOutlet OAuthTwitterDemoViewController *viewController; 20 | 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /Demo/Src/OAuthTwitterDemoAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAuthTwitterDemoAppDelegate.m 3 | // OAuthTwitterDemo 4 | // 5 | // Created by Ben Gottlieb on 7/24/09. 6 | // Copyright Stand Alone, Inc. 2009. All rights reserved. 7 | // 8 | 9 | #import "OAuthTwitterDemoAppDelegate.h" 10 | #import "OAuthTwitterDemoViewController.h" 11 | 12 | @implementation OAuthTwitterDemoAppDelegate 13 | 14 | @synthesize window; 15 | @synthesize viewController; 16 | 17 | 18 | - (void)applicationDidFinishLaunching:(UIApplication *)application { 19 | 20 | // Override point for customization after app launch 21 | window.rootViewController = viewController; 22 | [window makeKeyAndVisible]; 23 | } 24 | 25 | 26 | - (void)dealloc { 27 | [viewController release]; 28 | [window release]; 29 | [super dealloc]; 30 | } 31 | 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Demo/Src/OAuthTwitterDemoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAuthTwitterDemoViewController.h 3 | // OAuthTwitterDemo 4 | // 5 | // Created by Ben Gottlieb on 7/24/09. 6 | // Copyright Stand Alone, Inc. 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SA_OAuthTwitterController.h" 11 | 12 | @class SA_OAuthTwitterEngine; 13 | 14 | 15 | @interface OAuthTwitterDemoViewController : UIViewController { 16 | SA_OAuthTwitterEngine *_engine; 17 | 18 | } 19 | 20 | @end 21 | 22 | -------------------------------------------------------------------------------- /Demo/Src/OAuthTwitterDemoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAuthTwitterDemoViewController.m 3 | // OAuthTwitterDemo 4 | // 5 | // Created by Ben Gottlieb on 7/24/09. 6 | // Copyright Stand Alone, Inc. 2009. All rights reserved. 7 | // 8 | 9 | #import "OAuthTwitterDemoViewController.h" 10 | #import "SA_OAuthTwitterEngine.h" 11 | 12 | 13 | #define kOAuthConsumerKey @"" //REPLACE ME 14 | #define kOAuthConsumerSecret @"" //REPLACE ME 15 | 16 | @implementation OAuthTwitterDemoViewController 17 | 18 | 19 | 20 | //============================================================================================================================= 21 | #pragma mark SA_OAuthTwitterEngineDelegate 22 | - (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username { 23 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 24 | 25 | [defaults setObject: data forKey: @"authData"]; 26 | [defaults synchronize]; 27 | } 28 | 29 | - (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username { 30 | return [[NSUserDefaults standardUserDefaults] objectForKey: @"authData"]; 31 | } 32 | 33 | //============================================================================================================================= 34 | #pragma mark SA_OAuthTwitterControllerDelegate 35 | - (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username { 36 | NSLog(@"Authenicated for %@", username); 37 | } 38 | 39 | - (void) OAuthTwitterControllerFailed: (SA_OAuthTwitterController *) controller { 40 | NSLog(@"Authentication Failed!"); 41 | } 42 | 43 | - (void) OAuthTwitterControllerCanceled: (SA_OAuthTwitterController *) controller { 44 | NSLog(@"Authentication Canceled."); 45 | } 46 | 47 | //============================================================================================================================= 48 | #pragma mark TwitterEngineDelegate 49 | - (void) requestSucceeded: (NSString *) requestIdentifier { 50 | NSLog(@"Request %@ succeeded", requestIdentifier); 51 | } 52 | 53 | - (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error { 54 | NSLog(@"Request %@ failed with error: %@", requestIdentifier, error); 55 | } 56 | 57 | 58 | 59 | //============================================================================================================================= 60 | #pragma mark ViewController Stuff 61 | - (void)dealloc { 62 | [_engine release]; 63 | [super dealloc]; 64 | } 65 | - (void) viewDidAppear: (BOOL)animated { 66 | if (_engine) return; 67 | _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self]; 68 | _engine.consumerKey = kOAuthConsumerKey; 69 | _engine.consumerSecret = kOAuthConsumerSecret; 70 | 71 | UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self]; 72 | 73 | if (controller) 74 | [self presentViewController: controller animated: YES completion: nil]; 75 | else { 76 | [_engine sendUpdate: [NSString stringWithFormat: @"Already Updated. %@", [NSDate date]]]; 77 | } 78 | 79 | } 80 | 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /Demo/Src/OAuthTwitterDemo_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'OAuthTwitterDemo' target in the 'OAuthTwitterDemo' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /Demo/Src/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OAuthTwitterDemo 4 | // 5 | // Created by Ben Gottlieb on 7/24/09. 6 | // Copyright Stand Alone, Inc. 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | OAuthConsumer-iPhoneLib.xcodeproj/*.mode1v3 3 | OAuthConsumer-iPhoneLib.xcodeproj/*.pbxuser -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/BuildCombined.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | xcodebuild -target "OAuthLib" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos clean build 4 | xcodebuild -target "OAuthLib" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator clean build 5 | 6 | lipo -create "Build/Debug-iphoneos/libOAuthConsumer_iPhone.a" "Build/Debug-iphonesimulator/libOAuthConsumer_iPhone.a" -output "../Twitter+OAuth/Libraries & Headers/libOAuth.a" 7 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/Crypto/Base64Transcoder.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Base64Transcoder.c 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 "Base64Transcoder.h" 29 | 30 | #include 31 | #include 32 | 33 | const u_int8_t kBase64EncodeTable[64] = { 34 | /* 0 */ 'A', /* 1 */ 'B', /* 2 */ 'C', /* 3 */ 'D', 35 | /* 4 */ 'E', /* 5 */ 'F', /* 6 */ 'G', /* 7 */ 'H', 36 | /* 8 */ 'I', /* 9 */ 'J', /* 10 */ 'K', /* 11 */ 'L', 37 | /* 12 */ 'M', /* 13 */ 'N', /* 14 */ 'O', /* 15 */ 'P', 38 | /* 16 */ 'Q', /* 17 */ 'R', /* 18 */ 'S', /* 19 */ 'T', 39 | /* 20 */ 'U', /* 21 */ 'V', /* 22 */ 'W', /* 23 */ 'X', 40 | /* 24 */ 'Y', /* 25 */ 'Z', /* 26 */ 'a', /* 27 */ 'b', 41 | /* 28 */ 'c', /* 29 */ 'd', /* 30 */ 'e', /* 31 */ 'f', 42 | /* 32 */ 'g', /* 33 */ 'h', /* 34 */ 'i', /* 35 */ 'j', 43 | /* 36 */ 'k', /* 37 */ 'l', /* 38 */ 'm', /* 39 */ 'n', 44 | /* 40 */ 'o', /* 41 */ 'p', /* 42 */ 'q', /* 43 */ 'r', 45 | /* 44 */ 's', /* 45 */ 't', /* 46 */ 'u', /* 47 */ 'v', 46 | /* 48 */ 'w', /* 49 */ 'x', /* 50 */ 'y', /* 51 */ 'z', 47 | /* 52 */ '0', /* 53 */ '1', /* 54 */ '2', /* 55 */ '3', 48 | /* 56 */ '4', /* 57 */ '5', /* 58 */ '6', /* 59 */ '7', 49 | /* 60 */ '8', /* 61 */ '9', /* 62 */ '+', /* 63 */ '/' 50 | }; 51 | 52 | /* 53 | -1 = Base64 end of data marker. 54 | -2 = White space (tabs, cr, lf, space) 55 | -3 = Noise (all non whitespace, non-base64 characters) 56 | -4 = Dangerous noise 57 | -5 = Illegal noise (null byte) 58 | */ 59 | 60 | const int8_t kBase64DecodeTable[128] = { 61 | /* 0x00 */ -5, /* 0x01 */ -3, /* 0x02 */ -3, /* 0x03 */ -3, 62 | /* 0x04 */ -3, /* 0x05 */ -3, /* 0x06 */ -3, /* 0x07 */ -3, 63 | /* 0x08 */ -3, /* 0x09 */ -2, /* 0x0a */ -2, /* 0x0b */ -2, 64 | /* 0x0c */ -2, /* 0x0d */ -2, /* 0x0e */ -3, /* 0x0f */ -3, 65 | /* 0x10 */ -3, /* 0x11 */ -3, /* 0x12 */ -3, /* 0x13 */ -3, 66 | /* 0x14 */ -3, /* 0x15 */ -3, /* 0x16 */ -3, /* 0x17 */ -3, 67 | /* 0x18 */ -3, /* 0x19 */ -3, /* 0x1a */ -3, /* 0x1b */ -3, 68 | /* 0x1c */ -3, /* 0x1d */ -3, /* 0x1e */ -3, /* 0x1f */ -3, 69 | /* ' ' */ -2, /* '!' */ -3, /* '"' */ -3, /* '#' */ -3, 70 | /* '$' */ -3, /* '%' */ -3, /* '&' */ -3, /* ''' */ -3, 71 | /* '(' */ -3, /* ')' */ -3, /* '*' */ -3, /* '+' */ 62, 72 | /* ',' */ -3, /* '-' */ -3, /* '.' */ -3, /* '/' */ 63, 73 | /* '0' */ 52, /* '1' */ 53, /* '2' */ 54, /* '3' */ 55, 74 | /* '4' */ 56, /* '5' */ 57, /* '6' */ 58, /* '7' */ 59, 75 | /* '8' */ 60, /* '9' */ 61, /* ':' */ -3, /* ';' */ -3, 76 | /* '<' */ -3, /* '=' */ -1, /* '>' */ -3, /* '?' */ -3, 77 | /* '@' */ -3, /* 'A' */ 0, /* 'B' */ 1, /* 'C' */ 2, 78 | /* 'D' */ 3, /* 'E' */ 4, /* 'F' */ 5, /* 'G' */ 6, 79 | /* 'H' */ 7, /* 'I' */ 8, /* 'J' */ 9, /* 'K' */ 10, 80 | /* 'L' */ 11, /* 'M' */ 12, /* 'N' */ 13, /* 'O' */ 14, 81 | /* 'P' */ 15, /* 'Q' */ 16, /* 'R' */ 17, /* 'S' */ 18, 82 | /* 'T' */ 19, /* 'U' */ 20, /* 'V' */ 21, /* 'W' */ 22, 83 | /* 'X' */ 23, /* 'Y' */ 24, /* 'Z' */ 25, /* '[' */ -3, 84 | /* '\' */ -3, /* ']' */ -3, /* '^' */ -3, /* '_' */ -3, 85 | /* '`' */ -3, /* 'a' */ 26, /* 'b' */ 27, /* 'c' */ 28, 86 | /* 'd' */ 29, /* 'e' */ 30, /* 'f' */ 31, /* 'g' */ 32, 87 | /* 'h' */ 33, /* 'i' */ 34, /* 'j' */ 35, /* 'k' */ 36, 88 | /* 'l' */ 37, /* 'm' */ 38, /* 'n' */ 39, /* 'o' */ 40, 89 | /* 'p' */ 41, /* 'q' */ 42, /* 'r' */ 43, /* 's' */ 44, 90 | /* 't' */ 45, /* 'u' */ 46, /* 'v' */ 47, /* 'w' */ 48, 91 | /* 'x' */ 49, /* 'y' */ 50, /* 'z' */ 51, /* '{' */ -3, 92 | /* '|' */ -3, /* '}' */ -3, /* '~' */ -3, /* 0x7f */ -3 93 | }; 94 | 95 | const u_int8_t kBits_00000011 = 0x03; 96 | const u_int8_t kBits_00001111 = 0x0F; 97 | const u_int8_t kBits_00110000 = 0x30; 98 | const u_int8_t kBits_00111100 = 0x3C; 99 | const u_int8_t kBits_00111111 = 0x3F; 100 | const u_int8_t kBits_11000000 = 0xC0; 101 | const u_int8_t kBits_11110000 = 0xF0; 102 | const u_int8_t kBits_11111100 = 0xFC; 103 | 104 | size_t EstimateBas64EncodedDataSize(size_t inDataSize) 105 | { 106 | size_t theEncodedDataSize = (int)ceil(inDataSize / 3.0) * 4; 107 | theEncodedDataSize = theEncodedDataSize / 72 * 74 + theEncodedDataSize % 72; 108 | return(theEncodedDataSize); 109 | } 110 | 111 | size_t EstimateBas64DecodedDataSize(size_t inDataSize) 112 | { 113 | size_t theDecodedDataSize = (int)ceil(inDataSize / 4.0) * 3; 114 | //theDecodedDataSize = theDecodedDataSize / 72 * 74 + theDecodedDataSize % 72; 115 | return(theDecodedDataSize); 116 | } 117 | 118 | bool Base64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize) 119 | { 120 | size_t theEncodedDataSize = EstimateBas64EncodedDataSize(inInputDataSize); 121 | if (*ioOutputDataSize < theEncodedDataSize) 122 | return(false); 123 | *ioOutputDataSize = theEncodedDataSize; 124 | const u_int8_t *theInPtr = (const u_int8_t *)inInputData; 125 | u_int32_t theInIndex = 0, theOutIndex = 0; 126 | for (; theInIndex < (inInputDataSize / 3) * 3; theInIndex += 3) 127 | { 128 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2]; 129 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4]; 130 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (theInPtr[theInIndex + 2] & kBits_11000000) >> 6]; 131 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 2] & kBits_00111111) >> 0]; 132 | if (theOutIndex % 74 == 72) 133 | { 134 | outOutputData[theOutIndex++] = '\r'; 135 | outOutputData[theOutIndex++] = '\n'; 136 | } 137 | } 138 | const size_t theRemainingBytes = inInputDataSize - theInIndex; 139 | if (theRemainingBytes == 1) 140 | { 141 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2]; 142 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (0 & kBits_11110000) >> 4]; 143 | outOutputData[theOutIndex++] = '='; 144 | outOutputData[theOutIndex++] = '='; 145 | if (theOutIndex % 74 == 72) 146 | { 147 | outOutputData[theOutIndex++] = '\r'; 148 | outOutputData[theOutIndex++] = '\n'; 149 | } 150 | } 151 | else if (theRemainingBytes == 2) 152 | { 153 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2]; 154 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4]; 155 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (0 & kBits_11000000) >> 6]; 156 | outOutputData[theOutIndex++] = '='; 157 | if (theOutIndex % 74 == 72) 158 | { 159 | outOutputData[theOutIndex++] = '\r'; 160 | outOutputData[theOutIndex++] = '\n'; 161 | } 162 | } 163 | return(true); 164 | } 165 | 166 | bool Base64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize) 167 | { 168 | memset(ioOutputData, '.', *ioOutputDataSize); 169 | 170 | size_t theDecodedDataSize = EstimateBas64DecodedDataSize(inInputDataSize); 171 | if (*ioOutputDataSize < theDecodedDataSize) 172 | return(false); 173 | *ioOutputDataSize = 0; 174 | const u_int8_t *theInPtr = (const u_int8_t *)inInputData; 175 | u_int8_t *theOutPtr = (u_int8_t *)ioOutputData; 176 | size_t theInIndex = 0, theOutIndex = 0; 177 | u_int8_t theOutputOctet; 178 | size_t theSequence = 0; 179 | for (; theInIndex < inInputDataSize; ) 180 | { 181 | int8_t theSextet = 0; 182 | 183 | int8_t theCurrentInputOctet = theInPtr[theInIndex]; 184 | theSextet = kBase64DecodeTable[theCurrentInputOctet]; 185 | if (theSextet == -1) 186 | break; 187 | while (theSextet == -2) 188 | { 189 | theCurrentInputOctet = theInPtr[++theInIndex]; 190 | theSextet = kBase64DecodeTable[theCurrentInputOctet]; 191 | } 192 | while (theSextet == -3) 193 | { 194 | theCurrentInputOctet = theInPtr[++theInIndex]; 195 | theSextet = kBase64DecodeTable[theCurrentInputOctet]; 196 | } 197 | if (theSequence == 0) 198 | { 199 | theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 2 & kBits_11111100; 200 | } 201 | else if (theSequence == 1) 202 | { 203 | theOutputOctet |= (theSextet >- 0 ? theSextet : 0) >> 4 & kBits_00000011; 204 | theOutPtr[theOutIndex++] = theOutputOctet; 205 | } 206 | else if (theSequence == 2) 207 | { 208 | theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 4 & kBits_11110000; 209 | } 210 | else if (theSequence == 3) 211 | { 212 | theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 2 & kBits_00001111; 213 | theOutPtr[theOutIndex++] = theOutputOctet; 214 | } 215 | else if (theSequence == 4) 216 | { 217 | theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 6 & kBits_11000000; 218 | } 219 | else if (theSequence == 5) 220 | { 221 | theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 0 & kBits_00111111; 222 | theOutPtr[theOutIndex++] = theOutputOctet; 223 | } 224 | theSequence = (theSequence + 1) % 6; 225 | if (theSequence != 2 && theSequence != 4) 226 | theInIndex++; 227 | } 228 | *ioOutputDataSize = theOutIndex; 229 | return(true); 230 | } 231 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/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 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/Crypto/hmac.c: -------------------------------------------------------------------------------- 1 | // 2 | // hmac.c 3 | // OAuthConsumer 4 | // 5 | // Created by Jonathan Wight on 4/8/8. 6 | // Copyright 2008 Jonathan Wight. 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 | * Implementation of HMAC-SHA1. Adapted from example at http://tools.ietf.org/html/rfc2104 28 | 29 | */ 30 | 31 | #include "sha1.h" 32 | 33 | #include 34 | #include 35 | 36 | void hmac_sha1(const unsigned char *inText, size_t inTextLength, unsigned char* inKey, size_t inKeyLength, unsigned char *outDigest) 37 | { 38 | const size_t B = 64; 39 | const size_t L = 20; 40 | 41 | SHA1_CTX theSHA1Context; 42 | unsigned char k_ipad[B + 1]; /* inner padding - key XORd with ipad */ 43 | unsigned char k_opad[B + 1]; /* outer padding - key XORd with opad */ 44 | 45 | /* if key is longer than 64 bytes reset it to key=SHA1 (key) */ 46 | if (inKeyLength > B) 47 | { 48 | SHA1Init(&theSHA1Context); 49 | SHA1Update(&theSHA1Context, inKey, (unsigned int) inKeyLength); 50 | SHA1Final(inKey, &theSHA1Context); 51 | inKeyLength = L; 52 | } 53 | 54 | /* start out by storing key in pads */ 55 | memset(k_ipad, 0, sizeof k_ipad); 56 | memset(k_opad, 0, sizeof k_opad); 57 | memcpy(k_ipad, inKey, inKeyLength); 58 | memcpy(k_opad, inKey, inKeyLength); 59 | 60 | /* XOR key with ipad and opad values */ 61 | int i; 62 | for (i = 0; i < B; i++) 63 | { 64 | k_ipad[i] ^= 0x36; 65 | k_opad[i] ^= 0x5c; 66 | } 67 | 68 | /* 69 | * perform inner SHA1 70 | */ 71 | SHA1Init(&theSHA1Context); /* init context for 1st pass */ 72 | SHA1Update(&theSHA1Context, k_ipad, B); /* start with inner pad */ 73 | SHA1Update(&theSHA1Context, (unsigned char *)inText, (unsigned int) inTextLength); /* then text of datagram */ 74 | SHA1Final((unsigned char *)outDigest, &theSHA1Context); /* finish up 1st pass */ 75 | 76 | /* 77 | * perform outer SHA1 78 | */ 79 | SHA1Init(&theSHA1Context); /* init context for 2nd 80 | * pass */ 81 | SHA1Update(&theSHA1Context, k_opad, B); /* start with outer pad */ 82 | SHA1Update(&theSHA1Context, outDigest, L); /* then results of 1st 83 | * hash */ 84 | SHA1Final(outDigest, &theSHA1Context); /* finish up 2nd pass */ 85 | 86 | } -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/Crypto/hmac.h: -------------------------------------------------------------------------------- 1 | // 2 | // hmac.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jonathan Wight on 4/8/8. 6 | // Copyright 2008 Jonathan Wight. 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 | #ifndef HMAC_H 27 | #define HMAC_H 1 28 | 29 | extern void hmac_sha1(const unsigned char *inText, int inTextLength, unsigned char* inKey, const unsigned int inKeyLength, unsigned char *outDigest); 30 | 31 | #endif /* HMAC_H */ -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/Crypto/sha1.c: -------------------------------------------------------------------------------- 1 | /* 2 | SHA-1 in C 3 | By Steve Reid 4 | 100% Public Domain 5 | 6 | Test Vectors (from FIPS PUB 180-1) 7 | "abc" 8 | A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D 9 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 10 | 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 11 | A million repetitions of "a" 12 | 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F 13 | */ 14 | 15 | /* #define LITTLE_ENDIAN * This should be #define'd if true. */ 16 | #if __LITTLE_ENDIAN__ 17 | #define LITTLE_ENDIAN 18 | #endif 19 | 20 | #define SHA1HANDSOFF 21 | /* #define SHA1HANDSOFF * Copies data before messing with it. */ 22 | 23 | #include 24 | #include 25 | 26 | #include "sha1.h" 27 | 28 | void SHA1Transform(unsigned long state[5], unsigned char buffer[64]); 29 | 30 | #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) 31 | 32 | /* blk0() and blk() perform the initial expand. */ 33 | /* I got the idea of expanding during the round function from SSLeay */ 34 | #ifdef LITTLE_ENDIAN 35 | #define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ 36 | |(rol(block->l[i],8)&0x00FF00FF)) 37 | #else 38 | #define blk0(i) block->l[i] 39 | #endif 40 | #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ 41 | ^block->l[(i+2)&15]^block->l[i&15],1)) 42 | 43 | /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ 44 | #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); 45 | #define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); 46 | #define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); 47 | #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); 48 | #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); 49 | 50 | 51 | /* Hash a single 512-bit block. This is the core of the algorithm. */ 52 | 53 | void SHA1Transform(unsigned long state[5], unsigned char buffer[64]) 54 | { 55 | unsigned long a, b, c, d, e; 56 | typedef union { 57 | unsigned char c[64]; 58 | unsigned long l[16]; 59 | } CHAR64LONG16; 60 | CHAR64LONG16* block; 61 | #ifdef SHA1HANDSOFF 62 | static unsigned char workspace[64]; 63 | block = (CHAR64LONG16*)workspace; 64 | memcpy(block, buffer, 64); 65 | #else 66 | block = (CHAR64LONG16*)buffer; 67 | #endif 68 | /* Copy context->state[] to working vars */ 69 | a = state[0]; 70 | b = state[1]; 71 | c = state[2]; 72 | d = state[3]; 73 | e = state[4]; 74 | /* 4 rounds of 20 operations each. Loop unrolled. */ 75 | R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); 76 | R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); 77 | R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); 78 | R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); 79 | R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); 80 | R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); 81 | R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); 82 | R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); 83 | R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); 84 | R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); 85 | R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); 86 | R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); 87 | R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); 88 | R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); 89 | R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); 90 | R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); 91 | R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); 92 | R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); 93 | R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); 94 | R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); 95 | /* Add the working vars back into context.state[] */ 96 | state[0] += a; 97 | state[1] += b; 98 | state[2] += c; 99 | state[3] += d; 100 | state[4] += e; 101 | /* Wipe variables */ 102 | a = b = c = d = e = 0; 103 | } 104 | 105 | 106 | /* SHA1Init - Initialize new context */ 107 | 108 | void SHA1Init(SHA1_CTX* context) 109 | { 110 | /* SHA1 initialization constants */ 111 | context->state[0] = 0x67452301; 112 | context->state[1] = 0xEFCDAB89; 113 | context->state[2] = 0x98BADCFE; 114 | context->state[3] = 0x10325476; 115 | context->state[4] = 0xC3D2E1F0; 116 | context->count[0] = context->count[1] = 0; 117 | } 118 | 119 | 120 | /* Run your data through this. */ 121 | 122 | void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len) 123 | { 124 | unsigned long i, j; 125 | 126 | j = (context->count[0] >> 3) & 63; 127 | if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++; 128 | context->count[1] += (len >> 29); 129 | if ((j + len) > 63) { 130 | memcpy(&context->buffer[j], data, (i = 64-j)); 131 | SHA1Transform(context->state, context->buffer); 132 | for ( ; i + 63 < len; i += 64) { 133 | SHA1Transform(context->state, &data[i]); 134 | } 135 | j = 0; 136 | } 137 | else i = 0; 138 | memcpy(&context->buffer[j], &data[i], len - i); 139 | } 140 | 141 | 142 | /* Add padding and return the message digest. */ 143 | 144 | void SHA1Final(unsigned char digest[20], SHA1_CTX* context) 145 | { 146 | unsigned long i, j; 147 | unsigned char finalcount[8]; 148 | 149 | for (i = 0; i < 8; i++) { 150 | finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] 151 | >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ 152 | } 153 | SHA1Update(context, (unsigned char *)"\200", 1); 154 | while ((context->count[0] & 504) != 448) { 155 | SHA1Update(context, (unsigned char *)"\0", 1); 156 | } 157 | SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ 158 | for (i = 0; i < 20; i++) { 159 | digest[i] = (unsigned char) 160 | ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); 161 | } 162 | /* Wipe variables */ 163 | i = j = 0; 164 | memset(context->buffer, 0, 64); 165 | memset(context->state, 0, 20); 166 | memset(context->count, 0, 8); 167 | memset(&finalcount, 0, 8); 168 | #ifdef SHA1HANDSOFF /* make SHA1Transform overwrite it's own static vars */ 169 | SHA1Transform(context->state, context->buffer); 170 | #endif 171 | } 172 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/Crypto/sha1.h: -------------------------------------------------------------------------------- 1 | 2 | // From http://www.mirrors.wiretapped.net/security/cryptography/hashes/sha1/sha1.c 3 | 4 | typedef struct { 5 | unsigned long state[5]; 6 | unsigned long count[2]; 7 | unsigned char buffer[64]; 8 | } SHA1_CTX; 9 | 10 | extern void SHA1Init(SHA1_CTX* context); 11 | extern void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len); 12 | extern void SHA1Final(unsigned char digest[20], SHA1_CTX* context); 13 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/NSMutableURLRequest+Parameters.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSMutableURLRequest+Parameters.h 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | #import 26 | #import "OARequestParameter.h" 27 | #import "NSURL+Base.h" 28 | 29 | 30 | @interface NSMutableURLRequest (OAParameterAdditions) 31 | 32 | - (NSArray *)parameters; 33 | - (void)setParameters:(NSArray *)parameters; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/NSMutableURLRequest+Parameters.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSMutableURLRequest+Parameters.m 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | 26 | #import "NSMutableURLRequest+Parameters.h" 27 | 28 | 29 | @implementation NSMutableURLRequest (OAParameterAdditions) 30 | 31 | - (NSArray *)parameters 32 | { 33 | NSString *encodedParameters; 34 | BOOL shouldfree = NO; 35 | 36 | if ([[self HTTPMethod] isEqualToString:@"GET"] || [[self HTTPMethod] isEqualToString:@"DELETE"]) 37 | encodedParameters = [[self URL] query]; 38 | else 39 | { 40 | // POST, PUT 41 | shouldfree = YES; 42 | encodedParameters = [[NSString alloc] initWithData:[self HTTPBody] encoding:NSASCIIStringEncoding]; 43 | } 44 | 45 | if ((encodedParameters == nil) || ([encodedParameters isEqualToString:@""])) 46 | return nil; 47 | 48 | NSArray *encodedParameterPairs = [encodedParameters componentsSeparatedByString:@"&"]; 49 | NSMutableArray *requestParameters = [[NSMutableArray alloc] initWithCapacity:16]; 50 | 51 | for (NSString *encodedPair in encodedParameterPairs) 52 | { 53 | NSArray *encodedPairElements = [encodedPair componentsSeparatedByString:@"="]; 54 | OARequestParameter *parameter = [OARequestParameter requestParameterWithName:[[encodedPairElements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] 55 | value:[[encodedPairElements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 56 | [requestParameters addObject:parameter]; 57 | } 58 | 59 | // Cleanup 60 | if (shouldfree) 61 | [encodedParameters release]; 62 | 63 | return [requestParameters autorelease]; 64 | } 65 | 66 | - (void)setParameters:(NSArray *)parameters 67 | { 68 | NSMutableString *encodedParameterPairs = [NSMutableString stringWithCapacity:256]; 69 | 70 | int position = 1; 71 | for (OARequestParameter *requestParameter in parameters) 72 | { 73 | [encodedParameterPairs appendString:[requestParameter URLEncodedNameValuePair]]; 74 | if (position < [parameters count]) 75 | [encodedParameterPairs appendString:@"&"]; 76 | 77 | position++; 78 | } 79 | 80 | if ([[self HTTPMethod] isEqualToString:@"GET"] || [[self HTTPMethod] isEqualToString:@"DELETE"]) 81 | [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", [[self URL] URLStringWithoutQuery], encodedParameterPairs]]]; 82 | else 83 | { 84 | // POST, PUT 85 | NSData *postData = [encodedParameterPairs dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 86 | [self setHTTPBody:postData]; 87 | [self setValue:[NSString stringWithFormat:@"%d", (UInt16) [postData length]] forHTTPHeaderField:@"Content-Length"]; 88 | [self setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 89 | } 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/NSString+URLEncoding.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+URLEncoding.h 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | 26 | #import 27 | 28 | 29 | @interface NSString (OAURLEncodingAdditions) 30 | 31 | - (NSString *)URLEncodedString; 32 | - (NSString *)URLDecodedString; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/NSString+URLEncoding.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+URLEncoding.m 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | 26 | #import "NSString+URLEncoding.h" 27 | 28 | 29 | @implementation NSString (OAURLEncodingAdditions) 30 | 31 | - (NSString *)URLEncodedString 32 | { 33 | NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 34 | (CFStringRef)self, 35 | NULL, 36 | CFSTR("!*'();:@&=+$,/?%#[]"), 37 | kCFStringEncodingUTF8); 38 | [result autorelease]; 39 | return result; 40 | } 41 | 42 | - (NSString*)URLDecodedString 43 | { 44 | NSString *result = (NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, 45 | (CFStringRef)self, 46 | CFSTR(""), 47 | kCFStringEncodingUTF8); 48 | [result autorelease]; 49 | return result; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/NSURL+Base.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSURL+Base.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | 29 | 30 | @interface NSURL (OABaseAdditions) 31 | 32 | - (NSString *)URLStringWithoutQuery; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/NSURL+Base.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSURL+Base.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import "NSURL+Base.h" 28 | 29 | 30 | @implementation NSURL (OABaseAdditions) 31 | 32 | - (NSString *)URLStringWithoutQuery 33 | { 34 | NSArray *parts = [[self absoluteString] componentsSeparatedByString:@"?"]; 35 | return [parts objectAtIndex:0]; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAAsynchronousDataFetcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAAsynchronousDataFetcher.h 3 | // OAuthConsumer 4 | // 5 | // Created by Zsombor Szabó on 12/3/08. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | #import 26 | 27 | #import "OAMutableURLRequest.h" 28 | 29 | @interface OAAsynchronousDataFetcher : NSObject { 30 | OAMutableURLRequest *request; 31 | NSURLResponse *response; 32 | NSURLConnection *connection; 33 | NSMutableData *responseData; 34 | id delegate; 35 | SEL didFinishSelector; 36 | SEL didFailSelector; 37 | } 38 | 39 | + (id)asynchronousFetcherWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector; 40 | - (id)initWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector; 41 | 42 | - (void)start; 43 | - (void)cancel; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAAsynchronousDataFetcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAAsynchronousDataFetcher.m 3 | // OAuthConsumer 4 | // 5 | // Created by Zsombor Szabó on 12/3/08. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | #import "OAAsynchronousDataFetcher.h" 26 | 27 | #import "OAServiceTicket.h" 28 | 29 | @implementation OAAsynchronousDataFetcher 30 | 31 | + (id)asynchronousFetcherWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector 32 | { 33 | return [[[OAAsynchronousDataFetcher alloc] initWithRequest:aRequest delegate:aDelegate didFinishSelector:finishSelector didFailSelector:failSelector] autorelease]; 34 | } 35 | 36 | - (id)initWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector 37 | { 38 | if (self = [super init]) 39 | { 40 | request = [aRequest retain]; 41 | delegate = aDelegate; 42 | didFinishSelector = finishSelector; 43 | didFailSelector = failSelector; 44 | } 45 | return self; 46 | } 47 | 48 | - (void)start 49 | { 50 | [request prepare]; 51 | 52 | if (connection) 53 | [connection release]; 54 | 55 | connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 56 | 57 | if (connection) 58 | { 59 | if (responseData) 60 | [responseData release]; 61 | responseData = [[NSMutableData data] retain]; 62 | } 63 | else 64 | { 65 | OAServiceTicket *ticket= [[OAServiceTicket alloc] initWithRequest:request 66 | response:nil 67 | didSucceed:NO]; 68 | [delegate performSelector:didFailSelector 69 | withObject:ticket 70 | withObject:nil]; 71 | [ticket release]; 72 | } 73 | } 74 | 75 | - (void)cancel 76 | { 77 | if (connection) 78 | { 79 | [connection cancel]; 80 | [connection release]; 81 | connection = nil; 82 | } 83 | } 84 | 85 | - (void)dealloc 86 | { 87 | if (request) [request release]; 88 | if (connection) [connection release]; 89 | if (response) [response release]; 90 | if (responseData) [responseData release]; 91 | [super dealloc]; 92 | } 93 | 94 | #pragma mark - 95 | #pragma mark NSURLConnection methods 96 | 97 | - (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLResponse *)aResponse 98 | { 99 | if (response) 100 | [response release]; 101 | response = [aResponse retain]; 102 | [responseData setLength:0]; 103 | } 104 | 105 | - (void)connection:(NSURLConnection *)aConnection didReceiveData:(NSData *)data 106 | { 107 | [responseData appendData:data]; 108 | } 109 | 110 | - (void)connection:(NSURLConnection *)aConnection didFailWithError:(NSError *)error 111 | { 112 | OAServiceTicket *ticket= [[OAServiceTicket alloc] initWithRequest:request 113 | response:response 114 | didSucceed:NO]; 115 | [delegate performSelector:didFailSelector 116 | withObject:ticket 117 | withObject:error]; 118 | 119 | [ticket release]; 120 | } 121 | 122 | - (void)connectionDidFinishLoading:(NSURLConnection *)aConnection 123 | { 124 | OAServiceTicket *ticket = [[OAServiceTicket alloc] initWithRequest:request 125 | response:response 126 | didSucceed:[(NSHTTPURLResponse *)response statusCode] < 400]; 127 | [delegate performSelector:didFinishSelector 128 | withObject:ticket 129 | withObject:responseData]; 130 | 131 | [ticket release]; 132 | } 133 | 134 | @end 135 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAConsumer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAConsumer.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | 29 | 30 | @interface OAConsumer : NSObject { 31 | @protected 32 | NSString *key; 33 | NSString *secret; 34 | } 35 | @property(retain) NSString *key; 36 | @property(retain) NSString *secret; 37 | 38 | - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAConsumer.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAConsumer.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import "OAConsumer.h" 27 | 28 | 29 | @implementation OAConsumer 30 | @synthesize key, secret; 31 | 32 | #pragma mark init 33 | 34 | - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret 35 | { 36 | if (self = [super init]) 37 | { 38 | self.key = aKey; 39 | self.secret = aSecret; 40 | } 41 | return self; 42 | } 43 | 44 | - (void)dealloc 45 | { 46 | [key release]; 47 | [secret release]; 48 | [super dealloc]; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OADataFetcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // OADataFetcher.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 11/5/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 27 | #import "OAMutableURLRequest.h" 28 | #import "OAServiceTicket.h" 29 | 30 | 31 | @interface OADataFetcher : NSObject { 32 | @private 33 | OAMutableURLRequest *request; 34 | NSURLResponse *response; 35 | NSURLConnection *connection; 36 | NSError *error; 37 | NSData *responseData; 38 | id delegate; 39 | SEL didFinishSelector; 40 | SEL didFailSelector; 41 | } 42 | 43 | - (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OADataFetcher.m: -------------------------------------------------------------------------------- 1 | // 2 | // OADataFetcher.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 11/5/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import "OADataFetcher.h" 28 | 29 | 30 | @implementation OADataFetcher 31 | 32 | - (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest 33 | delegate:(id)aDelegate 34 | didFinishSelector:(SEL)finishSelector 35 | didFailSelector:(SEL)failSelector 36 | { 37 | request = aRequest; 38 | delegate = aDelegate; 39 | didFinishSelector = finishSelector; 40 | didFailSelector = failSelector; 41 | 42 | [request prepare]; 43 | 44 | responseData = [NSURLConnection sendSynchronousRequest:request 45 | returningResponse:&response 46 | error:&error]; 47 | 48 | if (response == nil || responseData == nil || error != nil) { 49 | OAServiceTicket *ticket= [[[OAServiceTicket alloc] initWithRequest:request 50 | response:response 51 | didSucceed:NO] autorelease]; 52 | [delegate performSelector:didFailSelector 53 | withObject:ticket 54 | withObject:error]; 55 | } else { 56 | OAServiceTicket *ticket = [[[OAServiceTicket alloc] initWithRequest:request 57 | response:response 58 | didSucceed:[(NSHTTPURLResponse *)response statusCode] < 400] autorelease]; 59 | [delegate performSelector:didFinishSelector 60 | withObject:ticket 61 | withObject:responseData]; 62 | } 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAHMAC_SHA1SignatureProvider.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAHMAC_SHA1SignatureProvider.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | #import "OASignatureProviding.h" 29 | 30 | 31 | @interface OAHMAC_SHA1SignatureProvider : NSObject 32 | @end 33 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAHMAC_SHA1SignatureProvider.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAHMAC_SHA1SignatureProvider.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import "OAHMAC_SHA1SignatureProvider.h" 28 | #import 29 | #include 30 | 31 | #include "hmac.h" 32 | #include "Base64Transcoder.h" 33 | 34 | @implementation OAHMAC_SHA1SignatureProvider 35 | 36 | - (NSString *)name 37 | { 38 | return @"HMAC-SHA1"; 39 | } 40 | 41 | - (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret 42 | { 43 | const char *cKey = [secret cStringUsingEncoding:NSASCIIStringEncoding]; 44 | const char *cData = [text cStringUsingEncoding:NSASCIIStringEncoding]; 45 | 46 | unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH]; 47 | 48 | CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC); 49 | 50 | NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC 51 | length:sizeof(cHMAC)]; 52 | 53 | NSString *hash = [HMAC base64EncodedStringWithOptions: 0]; 54 | return hash; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAMutableURLRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAMutableURLRequest.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | #import "OAConsumer.h" 29 | #import "OAToken.h" 30 | #import "OAHMAC_SHA1SignatureProvider.h" 31 | #import "OASignatureProviding.h" 32 | #import "NSMutableURLRequest+Parameters.h" 33 | #import "NSURL+Base.h" 34 | 35 | 36 | @interface OAMutableURLRequest : NSMutableURLRequest { 37 | @protected 38 | OAConsumer *consumer; 39 | OAToken *token; 40 | NSString *realm; 41 | NSString *signature; 42 | id signatureProvider; 43 | NSString *nonce; 44 | NSString *timestamp; 45 | } 46 | @property(readonly) NSString *signature; 47 | @property(readonly) NSString *nonce; 48 | @property(nonatomic, readwrite, retain) NSArray *parameters; 49 | 50 | - (id)initWithURL:(NSURL *)aUrl 51 | consumer:(OAConsumer *)aConsumer 52 | token:(OAToken *)aToken 53 | realm:(NSString *)aRealm 54 | signatureProvider:(id)aProvider; 55 | 56 | - (id)initWithURL:(NSURL *)aUrl 57 | consumer:(OAConsumer *)aConsumer 58 | token:(OAToken *)aToken 59 | realm:(NSString *)aRealm 60 | signatureProvider:(id)aProvider 61 | nonce:(NSString *)aNonce 62 | timestamp:(NSString *)aTimestamp; 63 | 64 | - (void)prepare; 65 | 66 | 67 | - (void)_generateTimestamp; 68 | - (void)_generateNonce; 69 | - (NSString *)_signatureBaseString; 70 | 71 | - (NSString *)URLStringWithoutQueryFromURL: (NSURL *) url; 72 | - (NSString *) URLEncodedString: (NSString *) string; 73 | @end 74 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAPlaintextSignatureProvider.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAPlaintextSignatureProvider.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | #import "OASignatureProviding.h" 29 | 30 | @interface OAPlaintextSignatureProvider : NSObject 31 | @end 32 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAPlaintextSignatureProvider.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAPlaintextSignatureProvider.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import "OAPlaintextSignatureProvider.h" 28 | #import "NSString+URLEncoding.h" 29 | 30 | 31 | @implementation OAPlaintextSignatureProvider 32 | 33 | - (NSString *)name 34 | { 35 | return @"PLAINTEXT"; 36 | } 37 | 38 | - (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret 39 | { 40 | return secret; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OARequestParameter.h: -------------------------------------------------------------------------------- 1 | // 2 | // OARequestParameter.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | #import "NSString+URLEncoding.h" 29 | 30 | 31 | @interface OARequestParameter : NSObject { 32 | @protected 33 | NSString *name; 34 | NSString *value; 35 | } 36 | @property(retain) NSString *name; 37 | @property(retain) NSString *value; 38 | 39 | + (id)requestParameterWithName:(NSString *)aName value:(NSString *)aValue; 40 | - (id)initWithName:(NSString *)aName value:(NSString *)aValue; 41 | - (NSString *)URLEncodedName; 42 | - (NSString *)URLEncodedValue; 43 | - (NSString *)URLEncodedNameValuePair; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OARequestParameter.m: -------------------------------------------------------------------------------- 1 | // 2 | // OARequestParameter.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import "OARequestParameter.h" 28 | 29 | 30 | @implementation OARequestParameter 31 | @synthesize name, value; 32 | 33 | + (id)requestParameterWithName:(NSString *)aName value:(NSString *)aValue 34 | { 35 | return [[[OARequestParameter alloc] initWithName:aName value:aValue] autorelease]; 36 | } 37 | 38 | - (id)initWithName:(NSString *)aName value:(NSString *)aValue 39 | { 40 | if (self = [super init]) 41 | { 42 | self.name = aName; 43 | self.value = aValue; 44 | } 45 | return self; 46 | } 47 | 48 | - (void)dealloc 49 | { 50 | [name release]; 51 | [value release]; 52 | [super dealloc]; 53 | } 54 | 55 | -(NSString *)urlEncode:(NSString*)stringThatNeedsEncoding 56 | { 57 | NSString *result = (NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)stringThatNeedsEncoding, NULL, CFSTR("!*'\"();:@&=+$,/?#[]%<>{} "), kCFStringEncodingUTF8); 58 | return [result autorelease]; 59 | } 60 | 61 | - (NSString *)URLEncodedName 62 | { 63 | return [self urlEncode:self.name]; //[self.name stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; 64 | } 65 | 66 | - (NSString *)URLEncodedValue 67 | { 68 | return [self urlEncode:self.value]; //[self.value stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; 69 | } 70 | 71 | - (NSString *)URLEncodedNameValuePair 72 | { 73 | return [NSString stringWithFormat:@"%@=%@", [self URLEncodedName], [self URLEncodedValue]]; 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAServiceTicket.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAServiceTicket.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 11/5/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | #import "OAMutableURLRequest.h" 29 | 30 | 31 | @interface OAServiceTicket : NSObject { 32 | @private 33 | OAMutableURLRequest *request; 34 | NSURLResponse *response; 35 | BOOL didSucceed; 36 | } 37 | @property(retain) OAMutableURLRequest *request; 38 | @property(retain) NSURLResponse *response; 39 | @property(assign) BOOL didSucceed; 40 | 41 | - (id)initWithRequest:(OAMutableURLRequest *)aRequest response:(NSURLResponse *)aResponse didSucceed:(BOOL)success; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAServiceTicket.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAServiceTicket.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 11/5/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import "OAServiceTicket.h" 28 | 29 | 30 | @implementation OAServiceTicket 31 | @synthesize request, response, didSucceed; 32 | 33 | - (id)initWithRequest:(OAMutableURLRequest *)aRequest response:(NSURLResponse *)aResponse didSucceed:(BOOL)success 34 | { 35 | if (self = [super init]) 36 | { 37 | self.request = aRequest; 38 | self.response = aResponse; 39 | self.didSucceed = success; 40 | } 41 | return self; 42 | } 43 | 44 | - (void)dealloc 45 | { 46 | [request release]; 47 | [response release]; 48 | [super dealloc]; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OASignatureProviding.h: -------------------------------------------------------------------------------- 1 | // 2 | // OASignatureProviding.h 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | 26 | #import 27 | 28 | 29 | @protocol OASignatureProviding 30 | 31 | - (NSString *)name; 32 | - (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAToken.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAToken.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 27 | 28 | @interface OAToken : NSObject { 29 | NSString *pin; //added for the Twitter OAuth implementation 30 | 31 | @protected 32 | NSString *key; 33 | NSString *secret; 34 | } 35 | @property(retain) NSString *pin; //added for the Twitter OAuth implementation 36 | 37 | @property(retain) NSString *key; 38 | @property(retain) NSString *secret; 39 | 40 | - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret; 41 | - (id)initWithUserDefaultsUsingServiceProviderName:(NSString *)provider prefix:(NSString *)prefix; 42 | - (id)initWithHTTPResponseBody:(NSString *)body; 43 | - (int)storeInUserDefaultsWithServiceProviderName:(NSString *)provider prefix:(NSString *)prefix; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAToken.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAToken.m 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import "OAToken.h" 28 | 29 | 30 | @implementation OAToken 31 | 32 | @synthesize key, secret; 33 | @synthesize pin; //added for the Twitter OAuth implementation 34 | 35 | #pragma mark init 36 | 37 | - (id)init 38 | { 39 | if (self = [super init]) 40 | { 41 | self.key = @""; 42 | self.secret = @""; 43 | } 44 | return self; 45 | } 46 | 47 | - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret 48 | { 49 | if (self = [super init]) 50 | { 51 | self.key = aKey; 52 | self.secret = aSecret; 53 | } 54 | return self; 55 | } 56 | 57 | - (id)initWithHTTPResponseBody:(NSString *)body 58 | { 59 | if (self = [super init]) 60 | { 61 | NSArray *pairs = [body componentsSeparatedByString:@"&"]; 62 | 63 | for (NSString *pair in pairs) { 64 | NSArray *elements = [pair componentsSeparatedByString:@"="]; 65 | if ([[elements objectAtIndex:0] isEqualToString:@"oauth_token"]) { 66 | self.key = [elements objectAtIndex:1]; 67 | } else if ([[elements objectAtIndex:0] isEqualToString:@"oauth_token_secret"]) { 68 | self.secret = [elements objectAtIndex:1]; 69 | } else if ([[elements objectAtIndex:0] isEqualToString:@"oauth_verifier"]) { 70 | self.pin = [elements objectAtIndex:1]; 71 | } 72 | } 73 | } 74 | return self; 75 | } 76 | 77 | - (id)initWithUserDefaultsUsingServiceProviderName:(NSString *)provider prefix:(NSString *)prefix 78 | { 79 | if (self = [super init]) 80 | { 81 | NSString *theKey = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"OAUTH_%@_%@_KEY", prefix, provider]]; 82 | NSString *theSecret = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"OAUTH_%@_%@_SECRET", prefix, provider]]; 83 | if (theKey == NULL || theSecret == NULL) 84 | return(nil); 85 | self.key = theKey; 86 | self.secret = theSecret; 87 | } 88 | return self; 89 | } 90 | 91 | - (void)dealloc 92 | { 93 | [key release]; 94 | [secret release]; 95 | [super dealloc]; 96 | } 97 | 98 | #pragma mark - 99 | 100 | - (int)storeInUserDefaultsWithServiceProviderName:(NSString *)provider prefix:(NSString *)prefix 101 | { 102 | [[NSUserDefaults standardUserDefaults] setObject:self.key forKey:[NSString stringWithFormat:@"OAUTH_%@_%@_KEY", prefix, provider]]; 103 | [[NSUserDefaults standardUserDefaults] setObject:self.secret forKey:[NSString stringWithFormat:@"OAUTH_%@_%@_SECRET", prefix, provider]]; 104 | [[NSUserDefaults standardUserDefaults] synchronize]; 105 | return(0); 106 | } 107 | 108 | @end 109 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAToken_KeychainExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAToken_KeychainExtensions.h 3 | // TouchTheFireEagle 4 | // 5 | // Created by Jonathan Wight on 04/04/08. 6 | // Copyright 2008 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "OAToken.h" 10 | 11 | #import 12 | 13 | @interface OAToken (OAToken_KeychainExtensions) 14 | 15 | - (id)initWithKeychainUsingAppName:(NSString *)name serviceProviderName:(NSString *)provider; 16 | - (int)storeInDefaultKeychainWithAppName:(NSString *)name serviceProviderName:(NSString *)provider; 17 | - (int)storeInKeychain:(SecKeychainRef)keychain appName:(NSString *)name serviceProviderName:(NSString *)provider; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAToken_KeychainExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // OAToken_KeychainExtensions.m 3 | // TouchTheFireEagle 4 | // 5 | // Created by Jonathan Wight on 04/04/08. 6 | // Copyright 2008 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "OAToken_KeychainExtensions.h" 10 | 11 | @implementation OAToken (OAToken_KeychainExtensions) 12 | 13 | - (id)initWithKeychainUsingAppName:(NSString *)name serviceProviderName:(NSString *)provider 14 | { 15 | [super init]; 16 | SecKeychainItemRef item; 17 | NSString *serviceName = [NSString stringWithFormat:@"%@::OAuth::%@", name, provider]; 18 | OSStatus status = SecKeychainFindGenericPassword(NULL, 19 | strlen([serviceName UTF8String]), 20 | [serviceName UTF8String], 21 | 0, 22 | NULL, 23 | NULL, 24 | NULL, 25 | &item); 26 | if (status != noErr) { 27 | return nil; 28 | } 29 | 30 | // from Advanced Mac OS X Programming, ch. 16 31 | UInt32 length; 32 | char *password; 33 | SecKeychainAttribute attributes[8]; 34 | SecKeychainAttributeList list; 35 | 36 | attributes[0].tag = kSecAccountItemAttr; 37 | attributes[1].tag = kSecDescriptionItemAttr; 38 | attributes[2].tag = kSecLabelItemAttr; 39 | attributes[3].tag = kSecModDateItemAttr; 40 | 41 | list.count = 4; 42 | list.attr = attributes; 43 | 44 | status = SecKeychainItemCopyContent(item, NULL, &list, &length, (void **)&password); 45 | 46 | if (status == noErr) { 47 | self.key = [NSString stringWithCString:list.attr[0].data 48 | length:list.attr[0].length]; 49 | if (password != NULL) { 50 | char passwordBuffer[1024]; 51 | 52 | if (length > 1023) { 53 | length = 1023; 54 | } 55 | strncpy(passwordBuffer, password, length); 56 | 57 | passwordBuffer[length] = '\0'; 58 | self.secret = [NSString stringWithCString:passwordBuffer]; 59 | } 60 | 61 | SecKeychainItemFreeContent(&list, password); 62 | 63 | } else { 64 | // TODO find out why this always works in i386 and always fails on ppc 65 | NSLog(@"Error from SecKeychainItemCopyContent: %d", status); 66 | return nil; 67 | } 68 | 69 | NSMakeCollectable(item); 70 | 71 | return self; 72 | } 73 | 74 | 75 | - (int)storeInDefaultKeychainWithAppName:(NSString *)name serviceProviderName:(NSString *)provider 76 | { 77 | return [self storeInKeychain:NULL appName:name serviceProviderName:provider]; 78 | } 79 | 80 | - (int)storeInKeychain:(SecKeychainRef)keychain appName:(NSString *)name serviceProviderName:(NSString *)provider 81 | { 82 | OSStatus status = SecKeychainAddGenericPassword(keychain, 83 | [name length] + [provider length] + 9, 84 | [[NSString stringWithFormat:@"%@::OAuth::%@", name, provider] UTF8String], 85 | [self.key length], 86 | [self.key UTF8String], 87 | [self.secret length], 88 | [self.secret UTF8String], 89 | NULL 90 | ); 91 | return status; 92 | } 93 | 94 | @end 95 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumerSrc/OAuthConsumer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAuthConsumer.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 27 | #import 28 | #import 29 | #import 30 | #import 31 | #import 32 | #import 33 | #import 34 | #import 35 | #import 36 | #import 37 | #import 38 | #import 39 | #import -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/OAuthConsumer_iPhone_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'CocoaTouchStaticLibrary' target in the 'CocoaTouchStaticLibrary' project. 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /OAuthConsumeriPhoneLib/ReadMe.txt: -------------------------------------------------------------------------------- 1 | To build a combined library for use in both the sim and on device, build both individual libraries, then cd to the build directory in terminal and execute the following: 2 | 3 | lipo -create Release-iphoneos/libOAuthConsumer_iPhone.a Debug-iphonesimulator/libOAuthConsumer_iPhone.a -output libOAuth.a 4 | -------------------------------------------------------------------------------- /ReadMe.txt: -------------------------------------------------------------------------------- 1 | Twitter+OAuth Source and Example for iPhone 2 | Glommed together by Ben Gottlieb 3 | copyright 2009-2015 Stand Alone, Inc - all rights reserved. 4 | License: BSD, If you use it, please include the following text somewhere in your application's user-facing text: 5 | "Includes Twitter+OAuth code by Ben Gottlieb" 6 | 7 | The goal of this was to create a drop-in code package for iPhone apps that want to access Twitter via OAuth. The main benefit here is that the source line on the Twitter page will say your app name, rather than "from web". 8 | 9 | This includes source taken from several other open frameworks, listed below. Most of the heavy lifting was all done by them, I just synthesized it into a (hopefully) easily digestible chunk. 10 | 11 | I decided not to do the whole thing as a static library since most developers are already using Matt Gemmell's MGTwitterEngine, and there was no reason to duplicate code. It adds about 200k to the final size of your project, mainly due to the OAuth library. 12 | 13 | Enjoy, and please let me know if you have any feedback! 14 | 15 | Ben Gottlieb 16 | ben@standalone.com 17 | 18 | == Major Changes Log == 19 | 2/14/15 - updated for 64 bit ARM and iOS 8 20 | 2/24/10 - added additional PIN checks in case Twitter changes the way they pass the PIN back 21 | - if all else fails, prompt the user to copy their PIN. The app will grab this and use it 22 | - this last part only works on OS 3.x and later, Everything else should work fine on 2.x. 23 | - integrated the latest build of MGTwitterEngine 24 | 25 | 26 | Example: 27 | Use the project in the Demo folder. You'll need to replace the strings in Demo/Src/OAuthTwitterDemoViewController.m with your own consumer key and consumer secret (visit http://twitter.com/oauth_clients/new to obtain these). 28 | 29 | 30 | Built using: 31 | MGTwitterEngine by Matt Gemmell 32 | http://mattgemmell.com 33 | License: http://mattgemmell.com/license 34 | I have included 1.0.8 release of the MGTwitterEngine unchanged in this project. 35 | The goal is to create an easily buildable project that has no dependancies. 36 | 37 | 38 | OAuthConsumer Framework 39 | Jon Crosby 40 | http://code.google.com/p/oauth/ 41 | License: http://www.apache.org/licenses/LICENSE-2.0 42 | I have included a pre-built binary of the OAuthConsumer Framework unchanged in this project. 43 | The goal is to create an easily buildable project that has no dependancies. 44 | 45 | 46 | OAuth-MyTwitter 47 | Chris Kimpton 48 | http://github.com/kimptoc/MGTwitterEngine-1.0.8-OAuth-MyTwitter/tree/master 49 | License: Couldn't find one. Will amend this if I do. 50 | Some code from this project was used to create the YHOATwitterEngine subclass of MGTwitterEngine. 51 | Thanks Chris, you made this project a simple! 52 | 53 | 54 | OAuth Test Application 55 | Isaiah Carew 56 | http://github.com/yourhead/OAuth_ObjC_Test_App/tree/master 57 | License: None found. 58 | Isaiah's test app worked great on the Mac, but didn't make use of the PIN number passed back by Twitter, and also needed to be re-worked to work on the phone. 59 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/NSMutableURLRequest+Parameters.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSMutableURLRequest+Parameters.h 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | #import 26 | #import "OARequestParameter.h" 27 | #import "NSURL+Base.h" 28 | 29 | 30 | @interface NSMutableURLRequest (OAParameterAdditions) 31 | 32 | - (NSArray *)parameters; 33 | - (void)setParameters:(NSArray *)parameters; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/NSString+URLEncoding.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+URLEncoding.h 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | 26 | #import 27 | 28 | 29 | @interface NSString (OAURLEncodingAdditions) 30 | 31 | - (NSString *)URLEncodedString; 32 | - (NSString *)URLDecodedString; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/NSURL+Base.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSURL+Base.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | 29 | 30 | @interface NSURL (OABaseAdditions) 31 | 32 | - (NSString *)URLStringWithoutQuery; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OAAsynchronousDataFetcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAAsynchronousDataFetcher.h 3 | // OAuthConsumer 4 | // 5 | // Created by Zsombor Szabó on 12/3/08. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | #import 26 | 27 | #import "OAMutableURLRequest.h" 28 | 29 | @interface OAAsynchronousDataFetcher : NSObject { 30 | OAMutableURLRequest *request; 31 | NSURLResponse *response; 32 | NSURLConnection *connection; 33 | NSMutableData *responseData; 34 | id delegate; 35 | SEL didFinishSelector; 36 | SEL didFailSelector; 37 | } 38 | 39 | + (id)asynchronousFetcherWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector; 40 | - (id)initWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector; 41 | 42 | - (void)start; 43 | - (void)cancel; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OAConsumer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAConsumer.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | 29 | 30 | @interface OAConsumer : NSObject { 31 | @protected 32 | NSString *key; 33 | NSString *secret; 34 | } 35 | @property(retain) NSString *key; 36 | @property(retain) NSString *secret; 37 | 38 | - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OADataFetcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // OADataFetcher.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 11/5/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 27 | #import "OAMutableURLRequest.h" 28 | #import "OAServiceTicket.h" 29 | 30 | 31 | @interface OADataFetcher : NSObject { 32 | @private 33 | OAMutableURLRequest *request; 34 | NSURLResponse *response; 35 | NSURLConnection *connection; 36 | NSError *error; 37 | NSData *responseData; 38 | id delegate; 39 | SEL didFinishSelector; 40 | SEL didFailSelector; 41 | } 42 | 43 | - (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OAHMAC_SHA1SignatureProvider.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAHMAC_SHA1SignatureProvider.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | #import "OASignatureProviding.h" 29 | 30 | 31 | @interface OAHMAC_SHA1SignatureProvider : NSObject 32 | @end 33 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OAMutableURLRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAMutableURLRequest.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | #import "OAConsumer.h" 29 | #import "OAToken.h" 30 | #import "OAHMAC_SHA1SignatureProvider.h" 31 | #import "OASignatureProviding.h" 32 | #import "NSMutableURLRequest+Parameters.h" 33 | #import "NSURL+Base.h" 34 | 35 | 36 | @interface OAMutableURLRequest : NSMutableURLRequest { 37 | @protected 38 | OAConsumer *consumer; 39 | OAToken *token; 40 | NSString *realm; 41 | NSString *signature; 42 | id signatureProvider; 43 | NSString *nonce; 44 | NSString *timestamp; 45 | } 46 | @property(readonly) NSString *signature; 47 | @property(readonly) NSString *nonce; 48 | 49 | - (id)initWithURL:(NSURL *)aUrl 50 | consumer:(OAConsumer *)aConsumer 51 | token:(OAToken *)aToken 52 | realm:(NSString *)aRealm 53 | signatureProvider:(id)aProvider; 54 | 55 | - (id)initWithURL:(NSURL *)aUrl 56 | consumer:(OAConsumer *)aConsumer 57 | token:(OAToken *)aToken 58 | realm:(NSString *)aRealm 59 | signatureProvider:(id)aProvider 60 | nonce:(NSString *)aNonce 61 | timestamp:(NSString *)aTimestamp; 62 | 63 | - (void)prepare; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OAPlaintextSignatureProvider.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAPlaintextSignatureProvider.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | #import "OASignatureProviding.h" 29 | 30 | @interface OAPlaintextSignatureProvider : NSObject 31 | @end 32 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OARequestParameter.h: -------------------------------------------------------------------------------- 1 | // 2 | // OARequestParameter.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | #import "NSString+URLEncoding.h" 29 | 30 | 31 | @interface OARequestParameter : NSObject { 32 | @protected 33 | NSString *name; 34 | NSString *value; 35 | } 36 | @property(retain) NSString *name; 37 | @property(retain) NSString *value; 38 | 39 | + (id)requestParameterWithName:(NSString *)aName value:(NSString *)aValue; 40 | - (id)initWithName:(NSString *)aName value:(NSString *)aValue; 41 | - (NSString *)URLEncodedName; 42 | - (NSString *)URLEncodedValue; 43 | - (NSString *)URLEncodedNameValuePair; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OAServiceTicket.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAServiceTicket.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 11/5/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 28 | #import "OAMutableURLRequest.h" 29 | 30 | 31 | @interface OAServiceTicket : NSObject { 32 | @private 33 | OAMutableURLRequest *request; 34 | NSURLResponse *response; 35 | BOOL didSucceed; 36 | } 37 | @property(retain) OAMutableURLRequest *request; 38 | @property(retain) NSURLResponse *response; 39 | @property(assign) BOOL didSucceed; 40 | 41 | - (id)initWithRequest:(OAMutableURLRequest *)aRequest response:(NSURLResponse *)aResponse didSucceed:(BOOL)success; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OASignatureProviding.h: -------------------------------------------------------------------------------- 1 | // 2 | // OASignatureProviding.h 3 | // 4 | // Created by Jon Crosby on 10/19/07. 5 | // Copyright 2007 Kaboomerang LLC. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | 26 | #import 27 | 28 | 29 | @protocol OASignatureProviding 30 | 31 | - (NSString *)name; 32 | - (NSString *)signClearText:(NSString *)text withSecret:(NSString *)secret; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OAToken.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAToken.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 27 | 28 | @interface OAToken : NSObject { 29 | NSString *pin; //added for the Twitter OAuth implementation 30 | 31 | @protected 32 | NSString *key; 33 | NSString *secret; 34 | } 35 | @property(retain) NSString *pin; //added for the Twitter OAuth implementation 36 | 37 | @property(retain) NSString *key; 38 | @property(retain) NSString *secret; 39 | 40 | - (id)initWithKey:(NSString *)aKey secret:(NSString *)aSecret; 41 | - (id)initWithUserDefaultsUsingServiceProviderName:(NSString *)provider prefix:(NSString *)prefix; 42 | - (id)initWithHTTPResponseBody:(NSString *)body; 43 | - (int)storeInUserDefaultsWithServiceProviderName:(NSString *)provider prefix:(NSString *)prefix; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OAToken_KeychainExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAToken_KeychainExtensions.h 3 | // TouchTheFireEagle 4 | // 5 | // Created by Jonathan Wight on 04/04/08. 6 | // Copyright 2008 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "OAToken.h" 10 | 11 | #import 12 | 13 | @interface OAToken (OAToken_KeychainExtensions) 14 | 15 | - (id)initWithKeychainUsingAppName:(NSString *)name serviceProviderName:(NSString *)provider; 16 | - (int)storeInDefaultKeychainWithAppName:(NSString *)name serviceProviderName:(NSString *)provider; 17 | - (int)storeInKeychain:(SecKeychainRef)keychain appName:(NSString *)name serviceProviderName:(NSString *)provider; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/OAuthConsumer/OAuthConsumer.h: -------------------------------------------------------------------------------- 1 | // 2 | // OAuthConsumer.h 3 | // OAuthConsumer 4 | // 5 | // Created by Jon Crosby on 10/19/07. 6 | // Copyright 2007 Kaboomerang LLC. 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 | #import 27 | #import "OAToken.h" 28 | #import "OAConsumer.h" 29 | #import "OAMutableURLRequest.h" 30 | #import "NSString+URLEncoding.h" 31 | #import "NSMutableURLRequest+Parameters.h" 32 | #import "NSURL+Base.h" 33 | #import "OASignatureProviding.h" 34 | #import "OAHMAC_SHA1SignatureProvider.h" 35 | #import "OAPlaintextSignatureProvider.h" 36 | #import "OARequestParameter.h" 37 | #import "OAServiceTicket.h" 38 | #import "OADataFetcher.h" 39 | #import "OAAsynchronousDataFetcher.h" -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/jQueryInject.txt: -------------------------------------------------------------------------------- 1 | $('html').css({'-webkit-background-size':'200px'}); 2 | $('body').css({'font-size':'12px','background':'#9AE4E8'}); 3 | $('#header').width(270); 4 | $('#header').height(46); 5 | $('.signin-content').css({'padding' : '15px','width' : '270px'}); 6 | $('#twitainer').width(270); 7 | $('#twitainer').css({'margin-left' : '8px'}); 8 | $('#login_form').width(30); 9 | $('#content').width(270); 10 | $('#content').css({'margin':'0px','float':'left'}); 11 | $('.tos').hide(); 12 | $('.newtos').remove(); 13 | $('.newtos').css({'text-align':'left', 'border':'1px solid red','color':'#555555','font-size':'12px','line-height':'1.3','margin':'20px 15px 5px'}); 14 | $('.newtos p').css({'margin' : '8px'}); 15 | $('h2').hide(); 16 | $('.oauth-errors').after("
" + $('.tos').html() + "
"); 17 | $("label:contains('Username or Email: ')").html("Username: "); 18 | $(".app-icon").attr({align : "right"}); 19 | $(".app-icon").css({'margin': '20px 0px 0px 0px;', 'border': '0px solid black', 'padding' : '-20px 0 0 10px'}); 20 | $('#signin_form .text').width(155); 21 | $('#signin_form .password').width(155); 22 | $('h4').after("
"); 23 | $('#signin_form').css({'padding-top': '0'}); 24 | $("h4").width(250); 25 | $("h4").css('font-size', '12px'); 26 | $("h4").html($("h4").html().replace(/This application/, '

This application')); 27 | $('.buttons').css({'margin-left' : '-17px' , 'width':'300'}); 28 | $('#deny').css({'-webkit-transform': 'scale(0.9)'}); 29 | $('#allow').css({'-webkit-transform': 'scale(0.9)'}); 30 | $('#oauth_pin').css({'-webkit-transform': 'scale(0.5)'}); 31 | $('.newtos').css({'border':'1px solid #A9BF74', 'background-color':'#E8FECD'}); 32 | $('.newtos p').css({'margin':'8px'}); 33 | 34 | // This rearranges the allow and deny buttons so that 35 | // the allow button is the first of the two input[type=submit] 36 | // This allows the "Go" button on the UIWebView's keyboard 37 | // to trigger an allow, instead of a deny. 38 | var deny = $( '#deny' ); 39 | var allow = $( '#allow' ); 40 | $('div.buttons').empty(); 41 | $('div.buttons').append( allow ); 42 | $('div.buttons').append( deny ); 43 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/jQueryInjectLandscape.txt: -------------------------------------------------------------------------------- 1 | $('html').css({'-webkit-background-size':'360px'}); 2 | $('body').css({'font-size':'12px','background':'#9AE4E8'}); 3 | $('#header').width(430); 4 | $('#header').height(10); 5 | $('.signin-content').css({'padding' : '15px','width' : '430px'}); 6 | $('#twitainer').width(430); 7 | $('#twitainer').css({'margin-left' : '8px'}); 8 | $('#login_form').width(30); 9 | $('#content').width(430); 10 | $('#content').css({'margin':'0px','float':'left'}); 11 | $('.tos').hide(); 12 | $('.newtos').remove(); 13 | $('.newtos').css({'text-align':'left', 'border':'1px solid red','color':'#555555','font-size':'12px','line-height':'1.3','margin':'20px 15px 5px'}); 14 | $('.newtos p').css({'margin' : '8px'}); 15 | $('h2').hide(); 16 | $('.oauth-errors').after("
" + $('.tos').html() + "
"); 17 | $("label:contains('Username or Email: ')").html("Username: "); 18 | $(".app-icon").attr({align : "right"}); 19 | $(".app-icon").css({'margin': '20px 0px 0px 0px;', 'border': '0px solid black', 'padding' : '-20px 0 0 10px'}); 20 | $('#signin_form .text').width(155); 21 | $('#signin_form .password').width(155); 22 | $('h4').after("
"); 23 | $('#signin_form').css({'padding-top': '0'}); 24 | $("h4").width(410); 25 | $("h4").css('font-size', '12px'); 26 | $("h4").html($("h4").html().replace(/This application/, '

This application')); 27 | $('.buttons').css({'margin-left' : '-17px' , 'width':'300'}); 28 | $('#deny').css({'-webkit-transform': 'scale(0.9)'}); 29 | $('#allow').css({'-webkit-transform': 'scale(0.9)'}); 30 | $('#oauth_pin').css({'-webkit-transform': 'scale(0.5)'}); 31 | $('.newtos').css({'border':'1px solid #A9BF74', 'background-color':'#E8FECD'}); 32 | $('.newtos p').css({'margin':'8px'}); 33 | 34 | // This rearranges the allow and deny buttons so that 35 | // the allow button is the first of the two input[type=submit] 36 | // This allows the "Go" button on the UIWebView's keyboard 37 | // to trigger an allow, instead of a deny. 38 | var deny = $( '#deny' ); 39 | var allow = $( '#allow' ); 40 | $('div.buttons').empty(); 41 | $('div.buttons').append( allow ); 42 | $('div.buttons').append( deny ); 43 | -------------------------------------------------------------------------------- /Twitter+OAuth/Libraries & Headers/libOAuth.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bengottlieb/Twitter-OAuth-iPhone/1e8d95c4e6f3f99352574b2448aa8c160ec9a323/Twitter+OAuth/Libraries & Headers/libOAuth.a -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterEngine.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterEngine.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 10/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterEngineDelegate.h" 12 | #import "MGTwitterParserDelegate.h" 13 | 14 | @interface MGTwitterEngine : NSObject { 15 | /*__weak*/ NSObject *_delegate; 16 | NSString *_username; 17 | NSString *_password; 18 | NSMutableDictionary *_connections; // MGTwitterHTTPURLConnection objects 19 | NSString *_clientName; 20 | NSString *_clientVersion; 21 | NSString *_clientURL; 22 | NSString *_clientSourceToken; 23 | NSString *_APIDomain; 24 | #if YAJL_AVAILABLE 25 | NSString *_searchDomain; 26 | #endif 27 | BOOL _secureConnection; 28 | BOOL _clearsCookies; 29 | #if YAJL_AVAILABLE 30 | MGTwitterEngineDeliveryOptions _deliveryOptions; 31 | #endif 32 | } 33 | 34 | #pragma mark Class management 35 | 36 | // Constructors 37 | + (MGTwitterEngine *)twitterEngineWithDelegate:(NSObject *)delegate; 38 | - (MGTwitterEngine *)initWithDelegate:(NSObject *)delegate; 39 | 40 | // Configuration and Accessors 41 | + (NSString *)version; // returns the version of MGTwitterEngine 42 | - (NSString *)username; 43 | - (NSString *)password; 44 | - (void)setUsername:(NSString *)username password:(NSString *)password; 45 | - (NSString *)clientName; // see README.txt for info on clientName/Version/URL/SourceToken 46 | - (NSString *)clientVersion; 47 | - (NSString *)clientURL; 48 | - (NSString *)clientSourceToken; 49 | - (void)setClientName:(NSString *)name version:(NSString *)version URL:(NSString *)url token:(NSString *)token; 50 | - (NSString *)APIDomain; 51 | - (void)setAPIDomain:(NSString *)domain; 52 | #if YAJL_AVAILABLE 53 | - (NSString *)searchDomain; 54 | - (void)setSearchDomain:(NSString *)domain; 55 | #endif 56 | - (BOOL)usesSecureConnection; // YES = uses HTTPS, default is YES 57 | - (void)setUsesSecureConnection:(BOOL)flag; 58 | - (BOOL)clearsCookies; // YES = deletes twitter.com cookies when setting username/password, default is NO (see README.txt) 59 | - (void)setClearsCookies:(BOOL)flag; 60 | #if YAJL_AVAILABLE 61 | - (MGTwitterEngineDeliveryOptions)deliveryOptions; 62 | - (void)setDeliveryOptions:(MGTwitterEngineDeliveryOptions)deliveryOptions; 63 | #endif 64 | 65 | // Connection methods 66 | - (NSUInteger)numberOfConnections; 67 | - (NSArray *)connectionIdentifiers; 68 | - (void)closeConnection:(NSString *)identifier; 69 | - (void)closeAllConnections; 70 | 71 | // Utility methods 72 | /// Note: the -getImageAtURL: method works for any image URL, not just Twitter images. 73 | // It does not require authentication, and is provided here for convenience. 74 | // As with the Twitter API methods below, it returns a unique connection identifier. 75 | // Retrieved images are sent to the delegate via the -imageReceived:forRequest: method. 76 | - (NSString *)getImageAtURL:(NSString *)urlString; 77 | 78 | #pragma mark REST API methods 79 | 80 | // ====================================================================================================== 81 | // Twitter REST API methods 82 | // See documentation at: http://apiwiki.twitter.com/Twitter-API-Documentation 83 | // All methods below return a unique connection identifier. 84 | // ====================================================================================================== 85 | 86 | // Status methods 87 | 88 | - (NSString *)getPublicTimeline; // statuses/public_timeline 89 | 90 | - (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/friends_timeline 91 | - (NSString *)getFollowedTimelineSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // statuses/friends_timeline 92 | 93 | - (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/user_timeline & statuses/user_timeline/user 94 | - (NSString *)getUserTimelineFor:(NSString *)username sinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // statuses/user_timeline & statuses/user_timeline/user 95 | 96 | - (NSString *)getUpdate:(unsigned long)updateID; // statuses/show 97 | - (NSString *)sendUpdate:(NSString *)status; // statuses/update 98 | - (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID; // statuses/update 99 | 100 | - (NSString *)getRepliesStartingAtPage:(int)pageNum; // statuses/mentions 101 | - (NSString *)getRepliesSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; // statuses/mentions 102 | - (NSString *)getRepliesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // statuses/mentions 103 | 104 | - (NSString *)deleteUpdate:(unsigned long)updateID; // statuses/destroy 105 | 106 | - (NSString *)getFeaturedUsers; // statuses/features (undocumented, returns invalid JSON data) 107 | 108 | 109 | // User methods 110 | 111 | - (NSString *)getRecentlyUpdatedFriendsFor:(NSString *)username startingAtPage:(int)pageNum; // statuses/friends & statuses/friends/user 112 | 113 | - (NSString *)getFollowersIncludingCurrentStatus:(BOOL)flag; // statuses/followers 114 | 115 | - (NSString *)getUserInformationFor:(NSString *)usernameOrID; // users/show 116 | - (NSString *)getUserInformationForEmail:(NSString *)email; // users/show 117 | 118 | 119 | // Direct Message methods 120 | 121 | - (NSString *)getDirectMessagesSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum; // direct_messages 122 | - (NSString *)getDirectMessagesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // direct_messages 123 | 124 | - (NSString *)getSentDirectMessagesSinceID:(unsigned long)sinceID startingAtPage:(int)pageNum; // direct_messages/sent 125 | - (NSString *)getSentDirectMessagesSinceID:(unsigned long)sinceID withMaximumID:(unsigned long)maxID startingAtPage:(int)pageNum count:(int)count; // direct_messages/sent 126 | 127 | - (NSString *)sendDirectMessage:(NSString *)message to:(NSString *)username; // direct_messages/new 128 | - (NSString *)deleteDirectMessage:(unsigned long)updateID;// direct_messages/destroy 129 | 130 | 131 | // Friendship methods 132 | 133 | - (NSString *)enableUpdatesFor:(NSString *)username; // friendships/create (follow username) 134 | - (NSString *)disableUpdatesFor:(NSString *)username; // friendships/destroy (unfollow username) 135 | - (NSString *)isUser:(NSString *)username1 receivingUpdatesFor:(NSString *)username2; // friendships/exists (test if username1 follows username2) 136 | 137 | 138 | // Account methods 139 | 140 | - (NSString *)checkUserCredentials; // account/verify_credentials 141 | - (NSString *)endUserSession; // account/end_session 142 | 143 | - (NSString *)setLocation:(NSString *)location; // account/update_location (deprecated, use account/update_profile instead) 144 | 145 | - (NSString *)setNotificationsDeliveryMethod:(NSString *)method; // account/update_delivery_device 146 | 147 | // TODO: Add: account/update_profile_colors 148 | // TODO: Add: account/update_profile_image 149 | // TODO: Add: account/update_profile_background_image 150 | 151 | - (NSString *)getRateLimitStatus; // account/rate_limit_status 152 | 153 | // TODO: Add: account/update_profile 154 | 155 | // - (NSString *)getUserUpdatesArchiveStartingAtPage:(int)pageNum; // account/archive (removed, use /statuses/user_timeline instead) 156 | 157 | 158 | // Favorite methods 159 | 160 | - (NSString *)getFavoriteUpdatesFor:(NSString *)username startingAtPage:(int)pageNum; // favorites 161 | 162 | - (NSString *)markUpdate:(unsigned long)updateID asFavorite:(BOOL)flag; // favorites/create, favorites/destroy 163 | 164 | 165 | // Notification methods 166 | 167 | - (NSString *)enableNotificationsFor:(NSString *)username; // notifications/follow 168 | - (NSString *)disableNotificationsFor:(NSString *)username; // notifications/leave 169 | 170 | 171 | // Block methods 172 | 173 | - (NSString *)block:(NSString *)username; // blocks/create 174 | - (NSString *)unblock:(NSString *)username; // blocks/destroy 175 | 176 | 177 | // Help methods 178 | 179 | - (NSString *)testService; // help/test 180 | 181 | - (NSString *)getDowntimeSchedule; // help/downtime_schedule (undocumented) 182 | 183 | 184 | #pragma mark Search API methods 185 | 186 | // ====================================================================================================== 187 | // Twitter Search API methods 188 | // See documentation at: http://apiwiki.twitter.com/Twitter-API-Documentation 189 | // All methods below return a unique connection identifier. 190 | // ====================================================================================================== 191 | 192 | #if YAJL_AVAILABLE 193 | 194 | // Search method 195 | 196 | - (NSString *)getSearchResultsForQuery:(NSString *)query; 197 | - (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count; // search 198 | - (NSString *)getSearchResultsForQuery:(NSString *)query sinceID:(unsigned long)sinceID startingAtPage:(int)pageNum count:(int)count geocode:(NSString *)geocode; 199 | 200 | // Trends method 201 | 202 | - (NSString *)getCurrentTrends; // current trends 203 | 204 | #endif 205 | 206 | @end 207 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterEngineDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterEngineDelegate.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 16/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | 12 | typedef enum _MGTwitterEngineDeliveryOptions { 13 | // all results will be delivered as an array via statusesReceived: and similar delegate methods 14 | MGTwitterEngineDeliveryAllResultsOption = 1 << 0, 15 | 16 | // individual results will be delivered as a dictionary via the receivedObject: delegate method 17 | MGTwitterEngineDeliveryIndividualResultsOption = 1 << 1, 18 | 19 | // these options can be combined with the | operator 20 | } MGTwitterEngineDeliveryOptions; 21 | 22 | 23 | 24 | @protocol MGTwitterEngineDelegate 25 | 26 | // These delegate methods are called after a connection has been established 27 | - (void)requestSucceeded:(NSString *)connectionIdentifier; 28 | - (void)requestFailed:(NSString *)connectionIdentifier withError:(NSError *)error; 29 | 30 | @optional 31 | 32 | #if YAJL_AVAILABLE 33 | // This delegate method is called each time a new result is parsed from the connection and 34 | // the deliveryOption is configured for MGTwitterEngineDeliveryIndividualResults. 35 | - (void)receivedObject:(NSDictionary *)dictionary forRequest:(NSString *)connectionIdentifier; 36 | #endif 37 | 38 | // These delegate methods are called after all results are parsed from the connection. If 39 | // the deliveryOption is configured for MGTwitterEngineDeliveryAllResults (the default), a 40 | // collection of all results is also returned. 41 | - (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier; 42 | - (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier; 43 | - (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier; 44 | - (void)miscInfoReceived:(NSArray *)miscInfo forRequest:(NSString *)connectionIdentifier; 45 | #if YAJL_AVAILABLE 46 | - (void)searchResultsReceived:(NSArray *)searchResults forRequest:(NSString *)connectionIdentifier; 47 | #endif 48 | 49 | #if TARGET_OS_IPHONE 50 | - (void)imageReceived:(UIImage *)image forRequest:(NSString *)connectionIdentifier; 51 | #else 52 | - (void)imageReceived:(NSImage *)image forRequest:(NSString *)connectionIdentifier; 53 | #endif 54 | 55 | // This delegate method is called whenever a connection has finished. 56 | - (void)connectionFinished:(NSString *)connectionIdentifier; 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterEngineGlobalHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterEngineGlobalHeader.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 09/08/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | /* 10 | This file conditionally includes the correct headers for either Mac OS X or iPhone deployment. 11 | */ 12 | 13 | #if TARGET_OS_IPHONE 14 | #import 15 | #import 16 | #else 17 | #import 18 | #endif 19 | 20 | /* 21 | Set YAJL_AVAILABLE to 1 if the YAJL JSON parser is available and you'd like MGTwitterEngine to use it. 22 | 23 | More information about this parser here: 24 | 25 | http://lloydforge.org/projects/yajl/ 26 | 27 | There are some speed advantages to using JSON instead of XML. Also, the Twitter Search API 28 | uses JSON, so adding this library to your project makes additional methods available to your 29 | application. 30 | 31 | Be aware, however, that the data types in the dictionaries returned by JSON may be different 32 | than the ones returned by XML. There is more type information in a JSON stream, so you may find 33 | that you get an NSNumber value instead of an NSString value for some keys in the dictionary. 34 | Make sure to test the new result sets in your application after switching from XML to JSON. 35 | 36 | Likewise, some keys may differ between the XML and JSON parsers. An example is the hourly limit 37 | returned by the getRateLimitStatus: method. For JSON, the key is "hourly_limit", for XML it is 38 | "hourly-limit". 39 | 40 | The event driven nature of the YAJL parser also allows delivery options to be specified. By 41 | default, all results are returned as an array of dictionaries. In some environments, such as the 42 | iPhone, the memory overhead of putting all the data into the array can be avoided by choosing 43 | the individual results option. This allows your application to process and store results without 44 | instantatiating a large collection and then enumerating over the items. 45 | 46 | If you want to use YAJL, change the following definition and make sure that the 47 | MGTwitterEngine*YAJLParser.m files are added to the Compile Sources phase of the MGTwitterEngine 48 | target. 49 | */ 50 | 51 | #define YAJL_AVAILABLE 0 52 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterHTTPURLConnection.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterHTTPURLConnection.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 16/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterRequestTypes.h" 12 | 13 | @interface MGTwitterHTTPURLConnection : NSURLConnection { 14 | NSMutableData *_data; // accumulated data received on this connection 15 | MGTwitterRequestType _requestType; // general type of this request, mostly for error handling 16 | MGTwitterResponseType _responseType; // type of response data expected (if successful) 17 | NSString *_identifier; 18 | NSURL *_URL; // the URL used for the connection (needed as a base URL when parsing with libxml) 19 | } 20 | 21 | // Initializer 22 | - (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate 23 | requestType:(MGTwitterRequestType)requestType responseType:(MGTwitterResponseType)responseType; 24 | 25 | // Data helper methods 26 | - (void)resetDataLength; 27 | - (void)appendData:(NSData *)data; 28 | 29 | // Accessors 30 | - (NSString *)identifier; 31 | - (NSData *)data; 32 | - (NSURL *)URL; 33 | - (MGTwitterRequestType)requestType; 34 | - (MGTwitterResponseType)responseType; 35 | - (NSString *)description; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterHTTPURLConnection.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterHTTPURLConnection.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 16/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterHTTPURLConnection.h" 10 | #import "NSString+UUID.h" 11 | 12 | 13 | @implementation MGTwitterHTTPURLConnection 14 | 15 | 16 | #pragma mark Initializer 17 | 18 | 19 | - (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate 20 | requestType:(MGTwitterRequestType)requestType responseType:(MGTwitterResponseType)responseType 21 | { 22 | if ((self = [super initWithRequest:request delegate:delegate])) { 23 | _data = [[NSMutableData alloc] initWithCapacity:0]; 24 | _identifier = [[NSString stringWithNewUUID] retain]; 25 | _requestType = requestType; 26 | _responseType = responseType; 27 | _URL = [[request URL] retain]; 28 | } 29 | 30 | return self; 31 | } 32 | 33 | 34 | - (void)dealloc 35 | { 36 | [_data release]; 37 | [_identifier release]; 38 | [_URL release]; 39 | [super dealloc]; 40 | } 41 | 42 | 43 | #pragma mark Data helper methods 44 | 45 | 46 | - (void)resetDataLength 47 | { 48 | [_data setLength:0]; 49 | } 50 | 51 | 52 | - (void)appendData:(NSData *)data 53 | { 54 | [_data appendData:data]; 55 | } 56 | 57 | 58 | #pragma mark Accessors 59 | 60 | 61 | - (NSString *)identifier 62 | { 63 | return [[_identifier retain] autorelease]; 64 | } 65 | 66 | 67 | - (NSData *)data 68 | { 69 | return [[_data retain] autorelease]; 70 | } 71 | 72 | 73 | - (NSURL *)URL 74 | { 75 | return [[_URL retain] autorelease]; 76 | } 77 | 78 | 79 | - (MGTwitterRequestType)requestType 80 | { 81 | return _requestType; 82 | } 83 | 84 | 85 | - (MGTwitterResponseType)responseType 86 | { 87 | return _responseType; 88 | } 89 | 90 | 91 | - (NSString *)description 92 | { 93 | NSString *description = [super description]; 94 | 95 | return [description stringByAppendingFormat:@" (requestType = %d, identifier = %@)", _requestType, _identifier]; 96 | } 97 | 98 | 99 | @end 100 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterLibXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterLibXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 18/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | #include 11 | 12 | #import "MGTwitterParserDelegate.h" 13 | 14 | @interface MGTwitterLibXMLParser : NSObject { 15 | /*__weak*/ NSObject *delegate; // weak ref 16 | NSString *identifier; 17 | MGTwitterRequestType requestType; 18 | MGTwitterResponseType responseType; 19 | NSURL *URL; 20 | NSData *xml; 21 | NSMutableArray *parsedObjects; 22 | 23 | xmlTextReaderPtr _reader; 24 | } 25 | 26 | + (id)parserWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 27 | connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType 28 | responseType:(MGTwitterResponseType)respType URL:(NSURL *)URL; 29 | - (id)initWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 30 | connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType 31 | responseType:(MGTwitterResponseType)respType URL:(NSURL *)URL; 32 | 33 | - (void)parse; 34 | 35 | // subclass utilities 36 | - (xmlChar *)_nodeValue; 37 | - (NSString *)_nodeValueAsString; 38 | - (NSDate *)_nodeValueAsDate; 39 | - (NSNumber *)_nodeValueAsInt; 40 | - (NSNumber *)_nodeValueAsBool; 41 | - (NSDictionary *)_statusDictionaryForNodeWithName:(const xmlChar *)parentNodeName; 42 | - (NSDictionary *)_userDictionaryForNodeWithName:(const xmlChar *)parentNodeName; 43 | - (NSDictionary *)_hashDictionaryForNodeWithName:(const xmlChar *)parentNodeName; 44 | 45 | // delegate callbacks 46 | - (void)_parsingDidEnd; 47 | - (void)_parsingErrorOccurred:(NSError *)parseError; 48 | 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterLibXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterLibXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 18/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | // Major portions derived from BSTweetParser by Brent Simmons 9 | // 10 | 11 | #import "MGTwitterLibXMLParser.h" 12 | 13 | 14 | @implementation MGTwitterLibXMLParser 15 | 16 | 17 | #pragma mark Creation and Destruction 18 | 19 | 20 | + (id)parserWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 21 | connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType 22 | responseType:(MGTwitterResponseType)respType URL:(NSURL *)URL 23 | { 24 | id parser = [[self alloc] initWithXML:theXML 25 | delegate:theDelegate 26 | connectionIdentifier:identifier 27 | requestType:reqType 28 | responseType:respType 29 | URL:URL]; 30 | 31 | return [parser autorelease]; 32 | } 33 | 34 | 35 | - (id)initWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 36 | connectionIdentifier:(NSString *)theIdentifier requestType:(MGTwitterRequestType)reqType 37 | responseType:(MGTwitterResponseType)respType URL:(NSURL *)theURL 38 | { 39 | if ((self = [super init])) 40 | { 41 | xml = [theXML retain]; 42 | identifier = [theIdentifier retain]; 43 | requestType = reqType; 44 | responseType = respType; 45 | URL = [theURL retain]; 46 | delegate = (id) theDelegate; 47 | parsedObjects = [[NSMutableArray alloc] initWithCapacity:0]; 48 | 49 | // setup the xml reader 50 | _reader = xmlReaderForMemory([xml bytes], (int) [xml length], [[URL absoluteString] UTF8String], nil, XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA | XML_PARSE_NOERROR | XML_PARSE_NOWARNING); 51 | if (! _reader) 52 | { 53 | return nil; 54 | } 55 | 56 | // run the parser and create parsedObjects 57 | [self parse]; 58 | 59 | // free the xml reader used for parsing 60 | xmlFree(_reader); 61 | 62 | // notify the delegate that parsing completed 63 | [self _parsingDidEnd]; 64 | } 65 | 66 | return self; 67 | } 68 | 69 | 70 | - (void)dealloc 71 | { 72 | [parsedObjects release]; 73 | [xml release]; 74 | [identifier release]; 75 | [URL release]; 76 | 77 | delegate = nil; 78 | [super dealloc]; 79 | } 80 | 81 | - (void)parse 82 | { 83 | // empty implementation -- override in subclasses 84 | } 85 | 86 | #pragma mark Subclass utilities 87 | 88 | // get the value from the current node 89 | - (xmlChar *)_nodeValue 90 | { 91 | if (xmlTextReaderIsEmptyElement(_reader)) 92 | { 93 | return nil; 94 | } 95 | 96 | xmlChar *result = nil; 97 | int nodeType = xmlTextReaderNodeType(_reader); 98 | while (nodeType != XML_READER_TYPE_END_ELEMENT) 99 | { 100 | if (nodeType == XML_READER_TYPE_TEXT) 101 | { 102 | result = xmlTextReaderValue(_reader); 103 | } 104 | 105 | // advance reader 106 | int readerResult = xmlTextReaderRead(_reader); 107 | if (readerResult != 1) 108 | { 109 | break; 110 | } 111 | nodeType = xmlTextReaderNodeType(_reader); 112 | } 113 | 114 | //NSLog(@"node: %25s = %s", xmlTextReaderConstName(_reader), result); 115 | 116 | return result; 117 | } 118 | 119 | - (NSString *)_nodeValueAsString 120 | { 121 | xmlChar *nodeValue = [self _nodeValue]; 122 | if (! nodeValue) 123 | { 124 | return nil; 125 | } 126 | 127 | NSMutableString *value = [NSMutableString stringWithUTF8String:(const char *)nodeValue]; 128 | xmlFree(nodeValue); 129 | 130 | // convert HTML entities back into UTF-8 131 | [value replaceOccurrencesOfString:@">" withString:@">" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [value length])]; 132 | [value replaceOccurrencesOfString:@"<" withString:@"<" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [value length])]; 133 | 134 | NSString *result = [NSString stringWithString:value]; 135 | return result; 136 | } 137 | 138 | - (NSDate *)_nodeValueAsDate 139 | { 140 | xmlChar *nodeValue = [self _nodeValue]; 141 | if (! nodeValue) 142 | { 143 | return nil; 144 | } 145 | 146 | struct tm theTime; 147 | strptime((char *)nodeValue, "%a %b %d %H:%M:%S +0000 %Y", &theTime); 148 | xmlFree(nodeValue); 149 | time_t epochTime = timegm(&theTime); 150 | return [NSDate dateWithTimeIntervalSince1970:epochTime]; 151 | } 152 | 153 | - (NSNumber *)_nodeValueAsInt 154 | { 155 | xmlChar *nodeValue = [self _nodeValue]; 156 | if (! nodeValue) 157 | { 158 | return nil; 159 | } 160 | 161 | NSString *intString = [NSString stringWithUTF8String:(const char *)nodeValue]; 162 | xmlFree(nodeValue); 163 | return [NSNumber numberWithInt:[intString intValue]]; 164 | } 165 | 166 | - (NSNumber *)_nodeValueAsBool 167 | { 168 | xmlChar *nodeValue = [self _nodeValue]; 169 | if (! nodeValue) 170 | { 171 | return nil; 172 | } 173 | 174 | NSString *boolString = [NSString stringWithUTF8String:(const char *)nodeValue]; 175 | xmlFree(nodeValue); 176 | return [NSNumber numberWithBool:[boolString isEqualToString:@"true"]]; 177 | } 178 | 179 | - (NSDictionary *)_statusDictionaryForNodeWithName:(const xmlChar *)parentNodeName 180 | { 181 | if (xmlTextReaderIsEmptyElement(_reader)) 182 | return nil; 183 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 184 | 185 | int readerResult = xmlTextReaderRead(_reader); 186 | if (readerResult != 1) 187 | return nil; 188 | int nodeType = xmlTextReaderNodeType(_reader); 189 | const xmlChar *name = xmlTextReaderConstName(_reader); 190 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name))) 191 | { 192 | if (nodeType == XML_READER_TYPE_ELEMENT) 193 | { 194 | if (xmlStrEqual(name, BAD_CAST "user")) 195 | { 196 | // "user" is the name of a sub-dictionary in each item 197 | [dictionary setObject:[self _userDictionaryForNodeWithName:name] forKey:@"user"]; 198 | } 199 | else if (xmlStrEqual(name, BAD_CAST "id") || xmlStrEqual(name, BAD_CAST "in_reply_to_user_id") || xmlStrEqual(name, BAD_CAST "in_reply_to_status_id")) 200 | { 201 | // process element as an integer 202 | NSNumber *number = [self _nodeValueAsInt]; 203 | if (number) 204 | { 205 | [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]]; 206 | } 207 | } 208 | else if (xmlStrEqual(name, BAD_CAST "created_at")) 209 | { 210 | // process element as a date 211 | NSDate *date = [self _nodeValueAsDate]; 212 | if (date) 213 | { 214 | [dictionary setObject:date forKey:[NSString stringWithUTF8String:(const char *)name]]; 215 | } 216 | } 217 | else if (xmlStrEqual(name, BAD_CAST "truncated") || xmlStrEqual(name, BAD_CAST "favorited")) 218 | { 219 | // process element as a boolean 220 | NSNumber *number = [self _nodeValueAsBool]; 221 | if (number) 222 | { 223 | [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]]; 224 | } 225 | } 226 | else 227 | { 228 | // process element as a string 229 | NSString *string = [self _nodeValueAsString]; 230 | if (string) 231 | { 232 | [dictionary setObject:string forKey:[NSString stringWithUTF8String:(const char *)name]]; 233 | } 234 | } 235 | } 236 | 237 | // advance reader 238 | int readerResult = xmlTextReaderRead(_reader); 239 | if (readerResult != 1) 240 | break; 241 | nodeType = xmlTextReaderNodeType(_reader); 242 | name = xmlTextReaderConstName(_reader); 243 | } 244 | 245 | // save the request type in the tweet 246 | [dictionary setObject:[NSNumber numberWithInt:requestType] forKey:TWITTER_SOURCE_REQUEST_TYPE]; 247 | 248 | return dictionary; 249 | } 250 | 251 | - (NSDictionary *)_userDictionaryForNodeWithName:(const xmlChar *)parentNodeName 252 | { 253 | if (xmlTextReaderIsEmptyElement(_reader)) 254 | return nil; 255 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 256 | 257 | int readerResult = xmlTextReaderRead(_reader); 258 | if (readerResult != 1) 259 | return nil; 260 | int nodeType = xmlTextReaderNodeType(_reader); 261 | const xmlChar *name = xmlTextReaderConstName(_reader); 262 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name))) 263 | { 264 | if (nodeType == XML_READER_TYPE_ELEMENT) 265 | { 266 | if (xmlStrEqual(name, BAD_CAST "id") || xmlStrEqual(name, BAD_CAST "followers_count") 267 | || xmlStrEqual(name, BAD_CAST "friends_count") || xmlStrEqual(name, BAD_CAST "favourites_count") 268 | || xmlStrEqual(name, BAD_CAST "statuses_count")) 269 | { 270 | // process element as an integer 271 | NSNumber *number = [self _nodeValueAsInt]; 272 | if (number) 273 | { 274 | [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]]; 275 | } 276 | } 277 | else if (xmlStrEqual(name, BAD_CAST "protected")) 278 | { 279 | // process element as a boolean 280 | NSNumber *number = [self _nodeValueAsBool]; 281 | if (number) 282 | { 283 | [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]]; 284 | } 285 | } 286 | else 287 | { 288 | // process element as a string 289 | NSString *s = [self _nodeValueAsString]; 290 | if (s) 291 | { 292 | [dictionary setObject:s forKey:[NSString stringWithUTF8String:(const char *)name]]; 293 | } 294 | } 295 | } 296 | 297 | // advance reader 298 | int readerResult = xmlTextReaderRead(_reader); 299 | if (readerResult != 1) 300 | break; 301 | nodeType = xmlTextReaderNodeType(_reader); 302 | name = xmlTextReaderConstName(_reader); 303 | } 304 | 305 | return dictionary; 306 | } 307 | 308 | - (NSDictionary *)_hashDictionaryForNodeWithName:(const xmlChar *)parentNodeName 309 | { 310 | if (xmlTextReaderIsEmptyElement(_reader)) 311 | return nil; 312 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 313 | 314 | int readerResult = xmlTextReaderRead(_reader); 315 | if (readerResult != 1) 316 | return nil; 317 | int nodeType = xmlTextReaderNodeType(_reader); 318 | const xmlChar *name = xmlTextReaderConstName(_reader); 319 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name))) 320 | { 321 | if (nodeType == XML_READER_TYPE_ELEMENT) 322 | { 323 | if (xmlStrEqual(name, BAD_CAST "hourly-limit") || xmlStrEqual(name, BAD_CAST "remaining-hits") 324 | || xmlStrEqual(name, BAD_CAST "reset-time-in-seconds")) 325 | { 326 | // process element as an integer 327 | NSNumber *number = [self _nodeValueAsInt]; 328 | if (number) 329 | { 330 | [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]]; 331 | } 332 | } 333 | else 334 | { 335 | // process element as a string 336 | NSString *s = [self _nodeValueAsString]; 337 | if (s) 338 | { 339 | [dictionary setObject:s forKey:[NSString stringWithUTF8String:(const char *)name]]; 340 | } 341 | } 342 | } 343 | 344 | // advance reader 345 | int readerResult = xmlTextReaderRead(_reader); 346 | if (readerResult != 1) 347 | break; 348 | nodeType = xmlTextReaderNodeType(_reader); 349 | name = xmlTextReaderConstName(_reader); 350 | } 351 | 352 | return dictionary; 353 | } 354 | 355 | 356 | #pragma mark Delegate callbacks 357 | 358 | - (void)_parsingDidEnd 359 | { 360 | //NSLog(@"Parsing complete: %@", parsedObjects); 361 | [delegate parsingSucceededForRequest:identifier ofResponseType:responseType withParsedObjects:parsedObjects]; 362 | } 363 | 364 | - (void)_parsingErrorOccurred:(NSError *)parseError 365 | { 366 | //NSLog(@"Parsing error occurred: %@", parseError); 367 | [delegate parsingFailedForRequest:identifier ofResponseType:responseType withError:parseError]; 368 | } 369 | 370 | @end 371 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterMessagesLibXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMessagesLibXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterLibXMLParser.h" 12 | 13 | @interface MGTwitterMessagesLibXMLParser : MGTwitterLibXMLParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterMessagesLibXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMessagesLibXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterMessagesLibXMLParser.h" 10 | 11 | 12 | @implementation MGTwitterMessagesLibXMLParser 13 | 14 | - (NSDictionary *)_directMessageDictionaryForNodeWithName:(const xmlChar *)parentNodeName { 15 | if (xmlTextReaderIsEmptyElement(_reader)) 16 | return nil; 17 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 18 | 19 | int readerResult = xmlTextReaderRead(_reader); 20 | if (readerResult != 1) 21 | return nil; 22 | int nodeType = xmlTextReaderNodeType(_reader); 23 | const xmlChar *name = xmlTextReaderConstName(_reader); 24 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name))) 25 | { 26 | if (nodeType == XML_READER_TYPE_ELEMENT) 27 | { 28 | if (xmlStrEqual(name, BAD_CAST "sender") || xmlStrEqual(name, BAD_CAST "recipient")) 29 | { 30 | // "user" is the name of a sub-dictionary in each item 31 | [dictionary setObject:[self _userDictionaryForNodeWithName:name] forKey:[NSString stringWithUTF8String:(const char *)name]]; 32 | } 33 | else if (xmlStrEqual(name, BAD_CAST "id") || xmlStrEqual(name, BAD_CAST "sender_id") || xmlStrEqual(name, BAD_CAST "recipient_id")) 34 | { 35 | // process element as an integer 36 | NSNumber *number = [self _nodeValueAsInt]; 37 | if (number) 38 | { 39 | [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]]; 40 | } 41 | } 42 | else if (xmlStrEqual(name, BAD_CAST "created_at")) 43 | { 44 | // process element as a date 45 | NSDate *date = [self _nodeValueAsDate]; 46 | if (date) 47 | { 48 | [dictionary setObject:date forKey:[NSString stringWithUTF8String:(const char *)name]]; 49 | } 50 | } 51 | else if (xmlStrEqual(name, BAD_CAST "protected")) 52 | { 53 | // process element as a boolean 54 | NSNumber *number = [self _nodeValueAsBool]; 55 | if (number) 56 | { 57 | [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]]; 58 | } 59 | } 60 | else 61 | { 62 | // process element as a string 63 | NSString *string = [self _nodeValueAsString]; 64 | if (string) 65 | { 66 | [dictionary setObject:string forKey:[NSString stringWithUTF8String:(const char *)name]]; 67 | } 68 | } 69 | } 70 | 71 | // advance reader 72 | int readerResult = xmlTextReaderRead(_reader); 73 | if (readerResult != 1) 74 | break; 75 | nodeType = xmlTextReaderNodeType(_reader); 76 | name = xmlTextReaderConstName(_reader); 77 | } 78 | 79 | // save the request type in the tweet 80 | [dictionary setObject:[NSNumber numberWithInt:requestType] forKey:TWITTER_SOURCE_REQUEST_TYPE]; 81 | 82 | return dictionary; 83 | } 84 | 85 | 86 | - (void)parse 87 | { 88 | int readerResult = xmlTextReaderRead(_reader); 89 | if (readerResult != 1) 90 | return; 91 | int nodeType = xmlTextReaderNodeType(_reader); 92 | const xmlChar *name = xmlTextReaderConstName(_reader); 93 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(BAD_CAST "direct-messages", name))) 94 | { 95 | if (nodeType == XML_READER_TYPE_ELEMENT) 96 | { 97 | if (xmlStrEqual(name, BAD_CAST "direct_message")) 98 | { 99 | [parsedObjects addObject:[self _directMessageDictionaryForNodeWithName:BAD_CAST "direct_message"]]; 100 | } 101 | } 102 | 103 | // advance reader 104 | int readerResult = xmlTextReaderRead(_reader); 105 | if (readerResult != 1) 106 | { 107 | break; 108 | } 109 | nodeType = xmlTextReaderNodeType(_reader); 110 | name = xmlTextReaderConstName(_reader); 111 | } 112 | } 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterMessagesParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMessagesParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 19/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterStatusesParser.h" 12 | 13 | @interface MGTwitterMessagesParser : MGTwitterStatusesParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterMessagesParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMessagesParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 19/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterMessagesParser.h" 10 | 11 | 12 | @implementation MGTwitterMessagesParser 13 | 14 | 15 | #pragma mark NSXMLParser delegate methods 16 | 17 | 18 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 19 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 20 | attributes:(NSDictionary *)attributeDict 21 | { 22 | //NSLog(@"Started element: %@ (%@)", elementName, attributeDict); 23 | [self setLastOpenedElement:elementName]; 24 | 25 | if ([elementName isEqualToString:@"direct_message"]) { 26 | // Make new entry in parsedObjects. 27 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 28 | [parsedObjects addObject:newNode]; 29 | currentNode = newNode; 30 | } else if ([elementName isEqualToString:@"sender"] || [elementName isEqualToString:@"recipient"]) { 31 | // Add an appropriate dictionary to current node. 32 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 33 | [currentNode setObject:newNode forKey:elementName]; 34 | currentNode = newNode; 35 | } else if (currentNode) { 36 | // Create relevant name-value pair. 37 | [currentNode setObject:[NSMutableString string] forKey:elementName]; 38 | } 39 | } 40 | 41 | 42 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 43 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 44 | { 45 | [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName]; 46 | 47 | if ([elementName isEqualToString:@"sender"] || [elementName isEqualToString:@"recipient"]) { 48 | currentNode = [parsedObjects lastObject]; 49 | } else if ([elementName isEqualToString:@"direct_message"]) { 50 | [self addSource]; 51 | currentNode = nil; 52 | } 53 | } 54 | 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterMiscLibXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMiscLibXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterLibXMLParser.h" 12 | 13 | @interface MGTwitterMiscLibXMLParser : MGTwitterLibXMLParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterMiscLibXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMiscLibXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterMiscLibXMLParser.h" 10 | 11 | 12 | @implementation MGTwitterMiscLibXMLParser 13 | 14 | - (void)parse 15 | { 16 | int readerResult = xmlTextReaderRead(_reader); 17 | if (readerResult != 1) 18 | return; 19 | 20 | int nodeType = xmlTextReaderNodeType(_reader); 21 | const xmlChar *name = xmlTextReaderConstName(_reader); 22 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT)) 23 | { 24 | if (nodeType == XML_READER_TYPE_ELEMENT) 25 | { 26 | if (xmlStrEqual(name, BAD_CAST "hash")) 27 | { 28 | [parsedObjects addObject:[self _hashDictionaryForNodeWithName:name]]; 29 | } 30 | else 31 | { 32 | // process element as a string -- API calls like friendships/exists.xml just return false or true 33 | NSString *string = [self _nodeValueAsString]; 34 | if (string) 35 | { 36 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 37 | [dictionary setObject:string forKey:[NSString stringWithUTF8String:(const char *)name]]; 38 | [parsedObjects addObject:dictionary]; 39 | } 40 | } 41 | } 42 | 43 | // advance reader 44 | int readerResult = xmlTextReaderRead(_reader); 45 | if (readerResult != 1) 46 | { 47 | break; 48 | } 49 | nodeType = xmlTextReaderNodeType(_reader); 50 | name = xmlTextReaderConstName(_reader); 51 | } 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterMiscParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMiscParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 06/06/2008. 6 | // Copyright 2008 Instinctive Code. All rights reserved. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterStatusesParser.h" 12 | 13 | @interface MGTwitterMiscParser : MGTwitterStatusesParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterMiscParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterMiscParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 06/06/2008. 6 | // Copyright 2008 Instinctive Code. All rights reserved. 7 | // 8 | 9 | #import "MGTwitterMiscParser.h" 10 | 11 | 12 | @implementation MGTwitterMiscParser 13 | 14 | 15 | #pragma mark NSXMLParser delegate methods 16 | 17 | 18 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 19 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 20 | attributes:(NSDictionary *)attributeDict 21 | { 22 | //NSLog(@"Started element: %@ (%@)", elementName, attributeDict); 23 | [self setLastOpenedElement:elementName]; 24 | 25 | if (!currentNode) { 26 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 27 | [parsedObjects addObject:newNode]; 28 | currentNode = newNode; 29 | } 30 | 31 | // Create relevant name-value pair. 32 | [currentNode setObject:[NSMutableString string] forKey:elementName]; 33 | } 34 | 35 | 36 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 37 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 38 | { 39 | [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName]; 40 | 41 | if ([elementName isEqualToString:@"remaining_hits"]) { 42 | NSNumber *hits = [NSNumber numberWithInt:[[currentNode objectForKey:elementName] intValue]]; 43 | [currentNode setObject:hits forKey:elementName]; 44 | } 45 | } 46 | 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterParserDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterParserDelegate.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 18/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterRequestTypes.h" 12 | 13 | @protocol MGTwitterParserDelegate 14 | 15 | - (void)parsingSucceededForRequest:(NSString *)identifier 16 | ofResponseType:(MGTwitterResponseType)responseType 17 | withParsedObjects:(NSArray *)parsedObjects; 18 | 19 | - (void)parsingFailedForRequest:(NSString *)requestIdentifier 20 | ofResponseType:(MGTwitterResponseType)responseType 21 | withError:(NSError *)error; 22 | 23 | #if YAJL_AVAILABLE 24 | - (void)parsedObject:(NSDictionary *)parsedObject forRequest:(NSString *)identifier 25 | ofResponseType:(MGTwitterResponseType)responseType; 26 | #endif 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterRequestTypes.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterEngineDelegate.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 17/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | typedef enum _MGTwitterRequestType { 12 | MGTwitterPublicTimelineRequest = 0, // latest statuses from the public timeline 13 | MGTwitterFollowedTimelineRequest, // latest statuses from the people that the current users follows 14 | MGTwitterUserTimelineRequest, // statuses archive for the current user 15 | MGTwitterUserTimelineForUserRequest, // statuses archive for the specified user 16 | MGTwitterUpdateGetRequest, // get a status update for the specified id 17 | MGTwitterUpdateSendRequest, // send a new update for the current user 18 | MGTwitterUpdateDeleteRequest, // delete an update for the current user using the specified id 19 | MGTwitterRepliesRequest, // latest reply status for the current user 20 | MGTwitterFeaturedUsersRequest, // latest status from featured users 21 | MGTwitterFriendUpdatesRequest, // last status for the people that the current user follows 22 | MGTwitterFriendUpdatesForUserRequest, // last status for the people that the specified user follows 23 | MGTwitterFollowerUpdatesRequest, // last status for the people that follow the current user 24 | MGTwitterUserInformationRequest, // user information using the specified id or email 25 | MGTwitterDirectMessagesRequest, // latest direct messages to the current user 26 | MGTwitterDirectMessagesSentRequest, // latest direct messages from the current user 27 | MGTwitterDirectMessageSendRequest, // send a new direct message from the current user 28 | MGTwitterDirectMessageDeleteRequest, // delete a direct message to/from the current user 29 | MGTwitterUpdatesEnableRequest, // enable status updates for specified user (e.g. follow) 30 | MGTwitterUpdatesDisableRequest, // disable status updates for specified user (e.g. unfollow) 31 | MGTwitterUpdatesCheckRequest, // check if the specified user is following another user 32 | MGTwitterAccountRequest, // changing account information for the current user 33 | MGTwitterAccountLocationRequest, // change location in account information for the current user 34 | MGTwitterAccountDeliveryRequest, // change notification delivery in account information for the current user 35 | MGTwitterAccountStatusRequest, // get rate limiting status for the current user 36 | MGTwitterFavoritesRequest, // latest favorites for the current user 37 | MGTwitterFavoritesForUserRequest, // latest favorites for the specified user 38 | MGTwitterFavoritesEnableRequest, // create a favorite for the current user using the specified id 39 | MGTwitterFavoritesDisableRequest, // remove a favorite for the current user using the specified id 40 | MGTwitterNotificationsEnableRequest, // enable notifications for the specified user 41 | MGTwitterNotificationsDisableRequest, // disable notifications for the specified user 42 | MGTwitterBlockEnableRequest, // enable block for the specified user 43 | MGTwitterBlockDisableRequest, // disable block for the specified user 44 | MGTwitterImageRequest, // requesting an image 45 | #if YAJL_AVAILABLE 46 | MGTwitterSearchRequest, // performing a search 47 | MGTwitterSearchCurrentTrendsRequest, // getting the current trends 48 | #endif 49 | } MGTwitterRequestType; 50 | 51 | typedef enum _MGTwitterResponseType { 52 | MGTwitterStatuses = 0, // one or more statuses 53 | MGTwitterStatus = 1, // exactly one status 54 | MGTwitterUsers = 2, // one or more user's information 55 | MGTwitterUser = 3, // info for exactly one user 56 | MGTwitterDirectMessages = 4, // one or more direct messages 57 | MGTwitterDirectMessage = 5, // exactly one direct message 58 | MGTwitterGeneric = 6, // a generic response not requiring parsing 59 | MGTwitterMiscellaneous = 8, // a miscellaneous response of key-value pairs 60 | MGTwitterImage = 7, // an image 61 | #if YAJL_AVAILABLE 62 | MGTwitterSearchResults = 9, // search results 63 | #endif 64 | } MGTwitterResponseType; 65 | 66 | // This key is added to each tweet or direct message returned, 67 | // with an NSNumber value containing an MGTwitterRequestType. 68 | // This is designed to help client applications aggregate updates. 69 | #define TWITTER_SOURCE_REQUEST_TYPE @"source_api_request_type" 70 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterStatusesLibXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterStatusesLibXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterLibXMLParser.h" 12 | 13 | @interface MGTwitterStatusesLibXMLParser : MGTwitterLibXMLParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterStatusesLibXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterStatusesLibXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterStatusesLibXMLParser.h" 10 | 11 | 12 | @implementation MGTwitterStatusesLibXMLParser 13 | 14 | 15 | - (void)parse 16 | { 17 | int readerResult = xmlTextReaderRead(_reader); 18 | if (readerResult != 1) 19 | return; 20 | int nodeType = xmlTextReaderNodeType(_reader); 21 | const xmlChar *name = xmlTextReaderConstName(_reader); 22 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(BAD_CAST "statuses", name))) 23 | { 24 | if (nodeType == XML_READER_TYPE_ELEMENT) 25 | { 26 | if (xmlStrEqual(name, BAD_CAST "status")) 27 | { 28 | [parsedObjects addObject:[self _statusDictionaryForNodeWithName:name]]; 29 | } 30 | } 31 | 32 | // advance reader 33 | int readerResult = xmlTextReaderRead(_reader); 34 | if (readerResult != 1) 35 | { 36 | break; 37 | } 38 | nodeType = xmlTextReaderNodeType(_reader); 39 | name = xmlTextReaderConstName(_reader); 40 | } 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterStatusesParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterStatusesParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterXMLParser.h" 12 | 13 | @interface MGTwitterStatusesParser : MGTwitterXMLParser { 14 | 15 | } 16 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 17 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName; 18 | @end 19 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterStatusesParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterStatusesParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterStatusesParser.h" 10 | 11 | 12 | @implementation MGTwitterStatusesParser 13 | 14 | 15 | #pragma mark NSXMLParser delegate methods 16 | 17 | 18 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 19 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 20 | attributes:(NSDictionary *)attributeDict 21 | { 22 | //NSLog(@"Started element: %@ (%@)", elementName, attributeDict); 23 | [self setLastOpenedElement:elementName]; 24 | 25 | if ([elementName isEqualToString:@"status"]) { 26 | // Make new entry in parsedObjects. 27 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 28 | [parsedObjects addObject:newNode]; 29 | currentNode = newNode; 30 | } else if ([elementName isEqualToString:@"user"]) { 31 | // Add a 'user' dictionary to current node. 32 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 33 | [currentNode setObject:newNode forKey:elementName]; 34 | currentNode = newNode; 35 | } else if (currentNode) { 36 | // Create relevant name-value pair. 37 | [currentNode setObject:[NSMutableString string] forKey:elementName]; 38 | } 39 | } 40 | 41 | 42 | - (void)parser:(NSXMLParser *)theParser foundCharacters:(NSString *)characters 43 | { 44 | //NSLog(@"Found characters: %@", characters); 45 | // Append found characters to value of lastOpenedElement in currentNode. 46 | if (lastOpenedElement && currentNode) { 47 | [[currentNode objectForKey:lastOpenedElement] appendString:characters]; 48 | } 49 | } 50 | 51 | 52 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 53 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 54 | { 55 | [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName]; 56 | 57 | if ([elementName isEqualToString:@"user"]) { 58 | currentNode = [parsedObjects lastObject]; 59 | } else if ([elementName isEqualToString:@"status"]) { 60 | [self addSource]; 61 | currentNode = nil; 62 | } 63 | } 64 | 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterUsersLibXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterUsersLibXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterLibXMLParser.h" 12 | 13 | @interface MGTwitterUsersLibXMLParser : MGTwitterLibXMLParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterUsersLibXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterUsersLibXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 11/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterUsersLibXMLParser.h" 10 | 11 | 12 | @implementation MGTwitterUsersLibXMLParser 13 | 14 | - (void)parse 15 | { 16 | int readerResult = xmlTextReaderRead(_reader); 17 | if (readerResult != 1) 18 | return; 19 | int nodeType = xmlTextReaderNodeType(_reader); 20 | const xmlChar *name = xmlTextReaderConstName(_reader); 21 | while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(BAD_CAST "users", name))) 22 | { 23 | if (nodeType == XML_READER_TYPE_ELEMENT) 24 | { 25 | if (xmlStrEqual(name, BAD_CAST "user")) 26 | { 27 | [parsedObjects addObject:[self _userDictionaryForNodeWithName:name]]; 28 | } 29 | } 30 | 31 | // advance reader 32 | int readerResult = xmlTextReaderRead(_reader); 33 | if (readerResult != 1) 34 | { 35 | break; 36 | } 37 | nodeType = xmlTextReaderNodeType(_reader); 38 | name = xmlTextReaderConstName(_reader); 39 | } 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterUsersParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterUsersParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 19/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterStatusesParser.h" 12 | 13 | @interface MGTwitterUsersParser : MGTwitterStatusesParser { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterUsersParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterUsersParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 19/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterUsersParser.h" 10 | 11 | 12 | @implementation MGTwitterUsersParser 13 | 14 | 15 | #pragma mark NSXMLParser delegate methods 16 | 17 | 18 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 19 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 20 | attributes:(NSDictionary *)attributeDict 21 | { 22 | //NSLog(@"Started element: %@ (%@)", elementName, attributeDict); 23 | [self setLastOpenedElement:elementName]; 24 | 25 | if ([elementName isEqualToString:@"user"]) { 26 | // Make new entry in parsedObjects. 27 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 28 | [parsedObjects addObject:newNode]; 29 | currentNode = newNode; 30 | } else if ([elementName isEqualToString:@"status"]) { 31 | // Add an appropriate dictionary to current node. 32 | NSMutableDictionary *newNode = [NSMutableDictionary dictionaryWithCapacity:0]; 33 | [currentNode setObject:newNode forKey:elementName]; 34 | currentNode = newNode; 35 | } else if (currentNode) { 36 | // Create relevant name-value pair. 37 | [currentNode setObject:[NSMutableString string] forKey:elementName]; 38 | } 39 | } 40 | 41 | 42 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 43 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 44 | { 45 | [super parser:theParser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qName]; 46 | 47 | if ([elementName isEqualToString:@"status"]) { 48 | currentNode = [parsedObjects lastObject]; 49 | } else if ([elementName isEqualToString:@"user"]) { 50 | [self addSource]; 51 | currentNode = nil; 52 | } 53 | } 54 | 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterXMLParser.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterXMLParser.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 18/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | #import "MGTwitterParserDelegate.h" 12 | 13 | @interface MGTwitterXMLParser : NSObject { 14 | __weak NSObject *delegate; // weak ref 15 | NSString *identifier; 16 | MGTwitterRequestType requestType; 17 | MGTwitterResponseType responseType; 18 | NSData *xml; 19 | NSMutableArray *parsedObjects; 20 | NSXMLParser *parser; 21 | __weak NSMutableDictionary *currentNode; 22 | NSString *lastOpenedElement; 23 | } 24 | 25 | + (id)parserWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 26 | connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType 27 | responseType:(MGTwitterResponseType)respType; 28 | - (id)initWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 29 | connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType 30 | responseType:(MGTwitterResponseType)respType; 31 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 32 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName; 33 | 34 | - (NSString *)lastOpenedElement; 35 | - (void)setLastOpenedElement:(NSString *)value; 36 | 37 | - (void)addSource; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/MGTwitterXMLParser.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGTwitterXMLParser.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 18/02/2008. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterXMLParser.h" 10 | 11 | 12 | @implementation MGTwitterXMLParser 13 | 14 | 15 | #pragma mark Creation and Destruction 16 | 17 | 18 | + (id)parserWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 19 | connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType 20 | responseType:(MGTwitterResponseType)respType 21 | { 22 | id parser = [[self alloc] initWithXML:theXML 23 | delegate:theDelegate 24 | connectionIdentifier:identifier 25 | requestType:reqType 26 | responseType:respType]; 27 | return [parser autorelease]; 28 | } 29 | 30 | 31 | - (id)initWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate 32 | connectionIdentifier:(NSString *)theIdentifier requestType:(MGTwitterRequestType)reqType 33 | responseType:(MGTwitterResponseType)respType 34 | { 35 | if ((self = [super init])) { 36 | xml = [theXML retain]; 37 | identifier = [theIdentifier retain]; 38 | requestType = reqType; 39 | responseType = respType; 40 | delegate = (id) theDelegate; 41 | parsedObjects = [[NSMutableArray alloc] initWithCapacity:0]; 42 | 43 | // Set up the parser object. 44 | parser = [[NSXMLParser alloc] initWithData:xml]; 45 | [parser setDelegate: (id)self]; 46 | [parser setShouldReportNamespacePrefixes:NO]; 47 | [parser setShouldProcessNamespaces:NO]; 48 | [parser setShouldResolveExternalEntities:NO]; 49 | 50 | // Begin parsing. 51 | [parser parse]; 52 | } 53 | 54 | return self; 55 | } 56 | 57 | 58 | - (void)dealloc 59 | { 60 | [parser release]; 61 | [parsedObjects release]; 62 | [xml release]; 63 | [identifier release]; 64 | delegate = nil; 65 | [super dealloc]; 66 | } 67 | 68 | 69 | #pragma mark NSXMLParser delegate methods 70 | 71 | 72 | - (void)parserDidStartDocument:(NSXMLParser *)theParser 73 | { 74 | //NSLog(@"Parsing begun"); 75 | } 76 | 77 | 78 | - (void)parserDidEndDocument:(NSXMLParser *)theParser 79 | { 80 | //NSLog(@"Parsing complete: %@", parsedObjects); 81 | [delegate parsingSucceededForRequest:identifier ofResponseType:responseType 82 | withParsedObjects:parsedObjects]; 83 | } 84 | 85 | 86 | - (void)parser:(NSXMLParser *)theParser didStartElement:(NSString *)elementName 87 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 88 | attributes:(NSDictionary *)attributeDict 89 | { 90 | //NSLog(@"Started element: %@ (%@)", elementName, attributeDict); 91 | } 92 | 93 | 94 | - (void)parser:(NSXMLParser *)theParser foundCharacters:(NSString *)characters 95 | { 96 | //NSLog(@"Found characters: %@", characters); 97 | } 98 | 99 | 100 | - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName 101 | namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 102 | { 103 | //NSLog(@"Ended element: %@", elementName); 104 | [self setLastOpenedElement:nil]; 105 | 106 | if ([elementName isEqualToString:@"protected"] 107 | || [elementName isEqualToString:@"truncated"] 108 | || [elementName isEqualToString:@"following"]) { 109 | // Change "true"/"false" into an NSNumber with a BOOL value. 110 | NSNumber *boolNumber = [NSNumber numberWithBool:[[currentNode objectForKey:elementName] isEqualToString:@"true"]]; 111 | [currentNode setObject:boolNumber forKey:elementName]; 112 | } else if ([elementName isEqualToString:@"created_at"]) { 113 | // Change date-string into an NSDate. 114 | #if !TARGET_OS_IPHONE 115 | NSDate *creationDate = [NSDate dateWithNaturalLanguageString:[currentNode objectForKey:elementName]]; 116 | if (creationDate) { 117 | [currentNode setObject:creationDate forKey:elementName]; 118 | } 119 | #endif 120 | } 121 | } 122 | 123 | 124 | - (void)parser:(NSXMLParser *)theParser foundAttributeDeclarationWithName:(NSString *)attributeName 125 | forElement:(NSString *)elementName type:(NSString *)type defaultValue:(NSString *)defaultValue 126 | { 127 | //NSLog(@"Found attribute: %@ (%@) [%@] {%@}", attributeName, elementName, type, defaultValue); 128 | } 129 | 130 | 131 | - (void)parser:(NSXMLParser *)theParser foundIgnorableWhitespace:(NSString *)whitespaceString 132 | { 133 | //NSLog(@"Found ignorable whitespace: %@", whitespaceString); 134 | } 135 | 136 | 137 | - (void)parser:(NSXMLParser *)theParser parseErrorOccurred:(NSError *)parseError 138 | { 139 | //NSLog(@"Parsing error occurred: %@", parseError); 140 | [delegate parsingFailedForRequest:identifier ofResponseType:responseType 141 | withError:parseError]; 142 | } 143 | 144 | 145 | #pragma mark Accessors 146 | 147 | 148 | - (NSString *)lastOpenedElement { 149 | return [[lastOpenedElement retain] autorelease]; 150 | } 151 | 152 | 153 | - (void)setLastOpenedElement:(NSString *)value { 154 | if (lastOpenedElement != value) { 155 | [lastOpenedElement release]; 156 | lastOpenedElement = [value copy]; 157 | } 158 | } 159 | 160 | 161 | #pragma mark Utility methods 162 | 163 | 164 | - (void)addSource 165 | { 166 | if (![currentNode objectForKey:TWITTER_SOURCE_REQUEST_TYPE]) { 167 | [currentNode setObject:[NSNumber numberWithInt:requestType] 168 | forKey:TWITTER_SOURCE_REQUEST_TYPE]; 169 | } 170 | } 171 | 172 | 173 | @end 174 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/NSData+Base64.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Base64.m 3 | // 4 | // Derived from http://colloquy.info/project/browser/trunk/NSDataAdditions.h?rev=1576 5 | // Created by khammond on Mon Oct 29 2001. 6 | // Formatted by Timothy Hatcher on Sun Jul 4 2004. 7 | // Copyright (c) 2001 Kyle Hammond. All rights reserved. 8 | // Original development by Dave Winer. 9 | // 10 | 11 | #import "MGTwitterEngineGlobalHeader.h" 12 | 13 | @interface NSData (Base64) 14 | 15 | /*! @function +dataWithBase64EncodedString: 16 | @discussion This method returns an autoreleased NSData object. The NSData object is initialized with the 17 | contents of the Base 64 encoded string. This is a convenience method. 18 | @param inBase64String An NSString object that contains only Base 64 encoded data. 19 | @result The NSData object. */ 20 | + (NSData *) dataWithBase64EncodedString:(NSString *) string; 21 | 22 | /*! @function -initWithBase64EncodedString: 23 | @discussion The NSData object is initialized with the contents of the Base 64 encoded string. 24 | This method returns self as a convenience. 25 | @param inBase64String An NSString object that contains only Base 64 encoded data. 26 | @result This method returns self. */ 27 | - (id) initWithBase64EncodedString:(NSString *) string; 28 | 29 | /*! @function -base64EncodingWithLineLength: 30 | @discussion This method returns a Base 64 encoded string representation of the data object. 31 | @param inLineLength A value of zero means no line breaks. This is crunched to a multiple of 4 (the next 32 | one greater than inLineLength). 33 | @result The base 64 encoded data. */ 34 | - (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength; 35 | 36 | @end -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/NSData+Base64.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Base64.m 3 | // 4 | // Derived from http://colloquy.info/project/browser/trunk/NSDataAdditions.h?rev=1576 5 | // Created by khammond on Mon Oct 29 2001. 6 | // Formatted by Timothy Hatcher on Sun Jul 4 2004. 7 | // Copyright (c) 2001 Kyle Hammond. All rights reserved. 8 | // Original development by Dave Winer. 9 | // 10 | 11 | #import "NSData+Base64.h" 12 | 13 | #import 14 | 15 | static char encodingTable[64] = { 16 | 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', 17 | 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', 18 | 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', 19 | 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' }; 20 | 21 | @implementation NSData (Base64) 22 | 23 | + (NSData *) dataWithBase64EncodedString:(NSString *) string { 24 | NSData *result = [[NSData alloc] initWithBase64EncodedString:string]; 25 | return [result autorelease]; 26 | } 27 | 28 | - (id) initWithBase64EncodedString:(NSString *) string { 29 | NSMutableData *mutableData = nil; 30 | 31 | if( string ) { 32 | unsigned long ixtext = 0; 33 | unsigned long lentext = 0; 34 | unsigned char ch = 0; 35 | unsigned char inbuf[4], outbuf[4]; 36 | short i = 0, ixinbuf = 0; 37 | BOOL flignore = NO; 38 | BOOL flendtext = NO; 39 | NSData *base64Data = nil; 40 | const unsigned char *base64Bytes = nil; 41 | 42 | // Convert the string to ASCII data. 43 | base64Data = [string dataUsingEncoding:NSASCIIStringEncoding]; 44 | base64Bytes = [base64Data bytes]; 45 | mutableData = [NSMutableData dataWithCapacity:[base64Data length]]; 46 | lentext = [base64Data length]; 47 | 48 | while( YES ) { 49 | if( ixtext >= lentext ) break; 50 | ch = base64Bytes[ixtext++]; 51 | flignore = NO; 52 | 53 | if( ( ch >= 'A' ) && ( ch <= 'Z' ) ) ch = ch - 'A'; 54 | else if( ( ch >= 'a' ) && ( ch <= 'z' ) ) ch = ch - 'a' + 26; 55 | else if( ( ch >= '0' ) && ( ch <= '9' ) ) ch = ch - '0' + 52; 56 | else if( ch == '+' ) ch = 62; 57 | else if( ch == '=' ) flendtext = YES; 58 | else if( ch == '/' ) ch = 63; 59 | else flignore = YES; 60 | 61 | if( ! flignore ) { 62 | short ctcharsinbuf = 3; 63 | BOOL flbreak = NO; 64 | 65 | if( flendtext ) { 66 | if( ! ixinbuf ) break; 67 | if( ( ixinbuf == 1 ) || ( ixinbuf == 2 ) ) ctcharsinbuf = 1; 68 | else ctcharsinbuf = 2; 69 | ixinbuf = 3; 70 | flbreak = YES; 71 | } 72 | 73 | inbuf [ixinbuf++] = ch; 74 | 75 | if( ixinbuf == 4 ) { 76 | ixinbuf = 0; 77 | outbuf [0] = ( inbuf[0] << 2 ) | ( ( inbuf[1] & 0x30) >> 4 ); 78 | outbuf [1] = ( ( inbuf[1] & 0x0F ) << 4 ) | ( ( inbuf[2] & 0x3C ) >> 2 ); 79 | outbuf [2] = ( ( inbuf[2] & 0x03 ) << 6 ) | ( inbuf[3] & 0x3F ); 80 | 81 | for( i = 0; i < ctcharsinbuf; i++ ) 82 | [mutableData appendBytes:&outbuf[i] length:1]; 83 | } 84 | 85 | if( flbreak ) break; 86 | } 87 | } 88 | } 89 | 90 | self = [self initWithData:mutableData]; 91 | return self; 92 | } 93 | 94 | - (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength { 95 | const unsigned char *bytes = [self bytes]; 96 | NSMutableString *result = [NSMutableString stringWithCapacity:[self length]]; 97 | unsigned long ixtext = 0; 98 | unsigned long lentext = [self length]; 99 | long ctremaining = 0; 100 | unsigned char inbuf[3], outbuf[4]; 101 | short i = 0; 102 | short charsonline = 0, ctcopy = 0; 103 | unsigned long ix = 0; 104 | 105 | while( YES ) { 106 | ctremaining = lentext - ixtext; 107 | if( ctremaining <= 0 ) break; 108 | 109 | for( i = 0; i < 3; i++ ) { 110 | ix = ixtext + i; 111 | if( ix < lentext ) inbuf[i] = bytes[ix]; 112 | else inbuf [i] = 0; 113 | } 114 | 115 | outbuf [0] = (inbuf [0] & 0xFC) >> 2; 116 | outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((inbuf [1] & 0xF0) >> 4); 117 | outbuf [2] = ((inbuf [1] & 0x0F) << 2) | ((inbuf [2] & 0xC0) >> 6); 118 | outbuf [3] = inbuf [2] & 0x3F; 119 | ctcopy = 4; 120 | 121 | switch( ctremaining ) { 122 | case 1: 123 | ctcopy = 2; 124 | break; 125 | case 2: 126 | ctcopy = 3; 127 | break; 128 | } 129 | 130 | for( i = 0; i < ctcopy; i++ ) 131 | [result appendFormat:@"%c", encodingTable[outbuf[i]]]; 132 | 133 | for( i = ctcopy; i < 4; i++ ) 134 | [result appendFormat:@"%c",'=']; 135 | 136 | ixtext += 3; 137 | charsonline += 4; 138 | 139 | if( lineLength > 0 ) { 140 | if (charsonline >= lineLength) { 141 | charsonline = 0; 142 | [result appendString:@"\n"]; 143 | } 144 | } 145 | } 146 | 147 | return result; 148 | } 149 | 150 | @end 151 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/NSString+UUID.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+UUID.h 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 16/09/2007. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "MGTwitterEngineGlobalHeader.h" 10 | 11 | @interface NSString (UUID) 12 | 13 | + (NSString*)stringWithNewUUID; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Twitter+OAuth/MGTwitterEngine/NSString+UUID.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+UUID.m 3 | // MGTwitterEngine 4 | // 5 | // Created by Matt Gemmell on 16/09/2007. 6 | // Copyright 2008 Instinctive Code. 7 | // 8 | 9 | #import "NSString+UUID.h" 10 | 11 | 12 | @implementation NSString (UUID) 13 | 14 | 15 | + (NSString*)stringWithNewUUID 16 | { 17 | // Create a new UUID 18 | CFUUIDRef uuidObj = CFUUIDCreate(nil); 19 | 20 | // Get the string representation of the UUID 21 | NSString *newUUID = (NSString*)CFUUIDCreateString(nil, uuidObj); 22 | CFRelease(uuidObj); 23 | return [newUUID autorelease]; 24 | } 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Twitter+OAuth/SAOAuthTwitterEngine/SA_OAuthTwitterController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SA_OAuthTwitterController.h 3 | // 4 | // Created by Ben Gottlieb on 24 July 2009. 5 | // Copyright 2009 Stand Alone, Inc. 6 | // 7 | // Some code and concepts taken from examples provided by 8 | // Matt Gemmell, Chris Kimpton, and Isaiah Carew 9 | // See ReadMe for further attributions, copyrights and license info. 10 | // 11 | 12 | #import 13 | 14 | @class SA_OAuthTwitterEngine, SA_OAuthTwitterController; 15 | 16 | @protocol SA_OAuthTwitterControllerDelegate 17 | @optional 18 | - (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username; 19 | - (void) OAuthTwitterControllerFailed: (SA_OAuthTwitterController *) controller; 20 | - (void) OAuthTwitterControllerCanceled: (SA_OAuthTwitterController *) controller; 21 | @end 22 | 23 | 24 | @interface SA_OAuthTwitterController : UIViewController { 25 | 26 | SA_OAuthTwitterEngine *_engine; 27 | UIWebView *_webView; 28 | UINavigationBar *_navBar; 29 | UIImageView *_backgroundView; 30 | 31 | id _delegate; 32 | UIView *_blockerView; 33 | 34 | UIInterfaceOrientation _orientation; 35 | BOOL _loading, _firstLoad; 36 | UIToolbar *_pinCopyPromptBar; 37 | } 38 | 39 | 40 | @property (nonatomic, readwrite, retain) SA_OAuthTwitterEngine *engine; 41 | @property (nonatomic, readwrite, assign) id delegate; 42 | @property (nonatomic, readonly) UINavigationBar *navigationBar; 43 | 44 | + (SA_OAuthTwitterController *) controllerToEnterCredentialsWithTwitterEngine: (SA_OAuthTwitterEngine *) engine delegate: (id ) delegate forOrientation:(UIInterfaceOrientation)theOrientation; 45 | + (SA_OAuthTwitterController *) controllerToEnterCredentialsWithTwitterEngine: (SA_OAuthTwitterEngine *) engine delegate: (id ) delegate; 46 | + (BOOL) credentialEntryRequiredWithTwitterEngine: (SA_OAuthTwitterEngine *) engine; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Twitter+OAuth/SAOAuthTwitterEngine/SA_OAuthTwitterEngine.h: -------------------------------------------------------------------------------- 1 | // 2 | // SA_OAuthTwitterEngine.h 3 | // 4 | // Created by Ben Gottlieb on 24 July 2009. 5 | // Copyright 2009 Stand Alone, Inc. 6 | // 7 | // Some code and concepts taken from examples provided by 8 | // Matt Gemmell, Chris Kimpton, and Isaiah Carew 9 | // See ReadMe for further attributions, copyrights and license info. 10 | // 11 | 12 | #import "MGTwitterEngine.h" 13 | 14 | @protocol SA_OAuthTwitterEngineDelegate 15 | @optional 16 | - (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username; //implement these methods to store off the creds returned by Twitter 17 | - (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username; //if you don't do this, the user will have to re-authenticate every time they run 18 | - (void) twitterOAuthConnectionFailedWithData: (NSData *) data; 19 | @end 20 | 21 | 22 | @class OAToken; 23 | @class OAConsumer; 24 | 25 | @interface SA_OAuthTwitterEngine : MGTwitterEngine { 26 | NSString *_consumerSecret; 27 | NSString *_consumerKey; 28 | NSURL *_requestTokenURL; 29 | NSURL *_accessTokenURL; 30 | NSURL *_authorizeURL; 31 | 32 | 33 | NSString *_pin; 34 | 35 | @private 36 | OAConsumer *_consumer; 37 | OAToken *_requestToken; 38 | OAToken *_accessToken; 39 | } 40 | 41 | @property (nonatomic, readwrite, retain) NSString *consumerSecret, *consumerKey; 42 | @property (nonatomic, readwrite, retain) NSURL *requestTokenURL, *accessTokenURL, *authorizeURL; //you shouldn't need to touch these. Just in case... 43 | @property (nonatomic, readonly) BOOL OAuthSetup; 44 | 45 | + (SA_OAuthTwitterEngine *) OAuthTwitterEngineWithDelegate: (NSObject *) delegate; 46 | - (SA_OAuthTwitterEngine *) initOAuthWithDelegate: (NSObject *) delegate; 47 | - (BOOL) isAuthorized; 48 | 49 | 50 | 51 | 52 | 53 | 54 | - (void) requestAccessToken; 55 | - (void) requestRequestToken; 56 | - (void) clearAccessToken; 57 | 58 | @property (nonatomic, readwrite, retain) NSString *pin; 59 | @property (nonatomic, readonly) NSURLRequest *authorizeURLRequest; 60 | @property (nonatomic, readonly) OAConsumer *consumer; 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Twitter+OAuth/SAOAuthTwitterEngine/twitter_load.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bengottlieb/Twitter-OAuth-iPhone/1e8d95c4e6f3f99352574b2448aa8c160ec9a323/Twitter+OAuth/SAOAuthTwitterEngine/twitter_load.png --------------------------------------------------------------------------------