Merge lp:~rockstar/ubuntuone-ios-music/kill-deps into lp:ubuntuone-ios-music

Proposed by Paul Hummer
Status: Merged
Approved by: Paul Hummer
Approved revision: 239
Merged at revision: 239
Proposed branch: lp:~rockstar/ubuntuone-ios-music/kill-deps
Merge into: lp:ubuntuone-ios-music
Diff against target: 482 lines (+7/-356)
7 files modified
Other Sources/U1MusicAppDelegate.m (+3/-15)
U1Music.xcodeproj/project.pbxproj (+0/-6)
U1Music_Prefix.pch (+0/-1)
utilities/SFHFKeychainUtils.h (+0/-41)
utilities/SFHFKeychainUtils.m (+0/-272)
utilities/Subsonic.h (+0/-1)
utilities/Subsonic.m (+4/-20)
To merge this branch: bzr merge lp:~rockstar/ubuntuone-ios-music/kill-deps
Reviewer Review Type Date Requested Status
Zachery Bir Approve
Review via email: mp+126340@code.launchpad.net

Commit message

Kill the need for SFHFKeychainUtils

Description of the change

This branch requires the changes in https://code.launchpad.net/~rockstar/ubuntuoneauthkit/more-cleanup/+merge/126339

Kill the need for SFHFKeychainUtils

To post a comment you must log in.
Revision history for this message
Zachery Bir (urbanape) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Other Sources/U1MusicAppDelegate.m'
--- Other Sources/U1MusicAppDelegate.m 2012-09-20 04:09:46 +0000
+++ Other Sources/U1MusicAppDelegate.m 2012-09-25 21:30:30 +0000
@@ -42,11 +42,11 @@
42#import "U1LocalMusicServer.h"42#import "U1LocalMusicServer.h"
43#import "U1MigrationViewController.h"43#import "U1MigrationViewController.h"
44#import "UOSSOCredentialsViewController.h"44#import "UOSSOCredentialsViewController.h"
45#import "UOAuthManager.h"
4546
46@interface U1MusicAppDelegate () <UOSSOCredentialsViewControllerDelegate>47@interface U1MusicAppDelegate () <UOSSOCredentialsViewControllerDelegate>
47@property (retain) UOSSOCredentialsViewController *loginController;48@property (retain) UOSSOCredentialsViewController *loginController;
48@property (retain) U1LocalMusicServer *musicServer;49@property (retain) U1LocalMusicServer *musicServer;
49- (void)parseQueryCredentials:(NSURL*)anURL;
50- (BOOL)configureUsernamePassword;50- (BOOL)configureUsernamePassword;
51- (void)presentLoginView;51- (void)presentLoginView;
52- (void)prepareTestFlight;52- (void)prepareTestFlight;
@@ -145,27 +145,15 @@
145 [self presentLoginView];145 [self presentLoginView];
146}146}
147147
148- (void)parseQueryCredentials:(NSURL*)anURL
149{
150 URLQueryStringParser *queryStringParser = [[URLQueryStringParser alloc] initWithURL:anURL];
151 NSString *user = [queryStringParser queryStringValueForKey:@"u"];
152 NSString *pass = [queryStringParser queryStringValueForKey:@"p"];
153
154 if (user != nil && pass != nil)
155 {
156 [[Subsonic sharedSubsonic] storeUsername:user password:pass];
157 }
158}
159
160- (BOOL)configureUsernamePassword148- (BOOL)configureUsernamePassword
161{149{
162 BOOL needToRetrieveCredentials = NO;150 BOOL needToRetrieveCredentials = NO;
163 151
164 NSString *username = [SFHFKeychainUtils getPasswordForUsername:UBUNTU_ONE_DUMMY_USER_NAME andServiceName:UBUNTU_ONE_SERVICE_NAME error:nil];152 NSString *username = [[UOAuthManager sharedAuthManager] subsonicUsername];
165 if (username)153 if (username)
166 {154 {
167 [[Subsonic sharedSubsonic] setDefaultUserName:username];155 [[Subsonic sharedSubsonic] setDefaultUserName:username];
168 [[Subsonic sharedSubsonic] setDefaultPassword:[SFHFKeychainUtils getPasswordForUsername:username andServiceName:UBUNTU_ONE_SERVICE_NAME error:nil]];156 [[Subsonic sharedSubsonic] setDefaultPassword:[[UOAuthManager sharedAuthManager] subsonicPassword]];
169 }157 }
170 else158 else
171 {159 {
172160
=== modified file 'U1Music.xcodeproj/project.pbxproj'
--- U1Music.xcodeproj/project.pbxproj 2012-09-20 04:07:45 +0000
+++ U1Music.xcodeproj/project.pbxproj 2012-09-25 21:30:30 +0000
@@ -171,7 +171,6 @@
171 93DFFE54135D72420061F29F /* NSManagedObjectContext+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 93DFFE53135D72420061F29F /* NSManagedObjectContext+Additions.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };171 93DFFE54135D72420061F29F /* NSManagedObjectContext+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 93DFFE53135D72420061F29F /* NSManagedObjectContext+Additions.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
172 93EE2AF0124993F100E7E060 /* ArtistListParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 93EE2AEF124993F100E7E060 /* ArtistListParser.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };172 93EE2AF0124993F100E7E060 /* ArtistListParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 93EE2AEF124993F100E7E060 /* ArtistListParser.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
173 93EE2BA31249F33D00E7E060 /* ArtistParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 93EE2BA21249F33D00E7E060 /* ArtistParser.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };173 93EE2BA31249F33D00E7E060 /* ArtistParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 93EE2BA21249F33D00E7E060 /* ArtistParser.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
174 93F334471247F9DE006C6707 /* SFHFKeychainUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F334461247F9DE006C6707 /* SFHFKeychainUtils.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
175 93F3344D1247FA0B006C6707 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F3344C1247FA0B006C6707 /* Reachability.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };174 93F3344D1247FA0B006C6707 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F3344C1247FA0B006C6707 /* Reachability.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
176 93F334521247FA2C006C6707 /* Album.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F3344F1247FA2C006C6707 /* Album.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };175 93F334521247FA2C006C6707 /* Album.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F3344F1247FA2C006C6707 /* Album.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
177 93F334531247FA2C006C6707 /* Artist.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F334511247FA2C006C6707 /* Artist.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };176 93F334531247FA2C006C6707 /* Artist.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F334511247FA2C006C6707 /* Artist.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
@@ -503,8 +502,6 @@
503 93EE2AEF124993F100E7E060 /* ArtistListParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ArtistListParser.m; sourceTree = "<group>"; };502 93EE2AEF124993F100E7E060 /* ArtistListParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ArtistListParser.m; sourceTree = "<group>"; };
504 93EE2BA11249F33D00E7E060 /* ArtistParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArtistParser.h; sourceTree = "<group>"; };503 93EE2BA11249F33D00E7E060 /* ArtistParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArtistParser.h; sourceTree = "<group>"; };
505 93EE2BA21249F33D00E7E060 /* ArtistParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ArtistParser.m; sourceTree = "<group>"; };504 93EE2BA21249F33D00E7E060 /* ArtistParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ArtistParser.m; sourceTree = "<group>"; };
506 93F334451247F9DE006C6707 /* SFHFKeychainUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SFHFKeychainUtils.h; sourceTree = "<group>"; };
507 93F334461247F9DE006C6707 /* SFHFKeychainUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SFHFKeychainUtils.m; sourceTree = "<group>"; };
508 93F3344B1247FA0B006C6707 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = "<group>"; };505 93F3344B1247FA0B006C6707 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = "<group>"; };
509 93F3344C1247FA0B006C6707 /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = "<group>"; };506 93F3344C1247FA0B006C6707 /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = "<group>"; };
510 93F3344E1247FA2C006C6707 /* Album.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Album.h; sourceTree = "<group>"; };507 93F3344E1247FA2C006C6707 /* Album.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Album.h; sourceTree = "<group>"; };
@@ -986,8 +983,6 @@
986 93F334741247FB9F006C6707 /* AudioStreamer.m */,983 93F334741247FB9F006C6707 /* AudioStreamer.m */,
987 93F3344B1247FA0B006C6707 /* Reachability.h */,984 93F3344B1247FA0B006C6707 /* Reachability.h */,
988 93F3344C1247FA0B006C6707 /* Reachability.m */,985 93F3344C1247FA0B006C6707 /* Reachability.m */,
989 93F334451247F9DE006C6707 /* SFHFKeychainUtils.h */,
990 93F334461247F9DE006C6707 /* SFHFKeychainUtils.m */,
991 93BC52A5124C1E6900B7587C /* StreamingPlayer.h */,986 93BC52A5124C1E6900B7587C /* StreamingPlayer.h */,
992 93BC52A6124C1E6900B7587C /* StreamingPlayer.m */,987 93BC52A6124C1E6900B7587C /* StreamingPlayer.m */,
993 93D6B5491252CE57007880B0 /* URLQueryStringParser.h */,988 93D6B5491252CE57007880B0 /* URLQueryStringParser.h */,
@@ -1395,7 +1390,6 @@
1395 936F20681227364200070F43 /* Playlist.m in Sources */,1390 936F20681227364200070F43 /* Playlist.m in Sources */,
1396 936F209012273D9000070F43 /* Song.m in Sources */,1391 936F209012273D9000070F43 /* Song.m in Sources */,
1397 936F230A12284D1900070F43 /* NamedTextFieldCell.m in Sources */,1392 936F230A12284D1900070F43 /* NamedTextFieldCell.m in Sources */,
1398 93F334471247F9DE006C6707 /* SFHFKeychainUtils.m in Sources */,
1399 93F3344D1247FA0B006C6707 /* Reachability.m in Sources */,1393 93F3344D1247FA0B006C6707 /* Reachability.m in Sources */,
1400 93F334521247FA2C006C6707 /* Album.m in Sources */,1394 93F334521247FA2C006C6707 /* Album.m in Sources */,
1401 93F334531247FA2C006C6707 /* Artist.m in Sources */,1395 93F334531247FA2C006C6707 /* Artist.m in Sources */,
14021396
=== modified file 'U1Music_Prefix.pch'
--- U1Music_Prefix.pch 2012-02-10 17:38:18 +0000
+++ U1Music_Prefix.pch 2012-09-25 21:30:30 +0000
@@ -16,7 +16,6 @@
16 #import "MOC.h"16 #import "MOC.h"
17 #import "NSManagedObjectContext+Additions.h"17 #import "NSManagedObjectContext+Additions.h"
18 #import "NSString+Extras.h"18 #import "NSString+Extras.h"
19 #import "SFHFKeychainUtils.h"
20 #import "TestFlight.h"19 #import "TestFlight.h"
21 #define RELEASE_SAFELY(__obj) [__obj release], __obj = nil;20 #define RELEASE_SAFELY(__obj) [__obj release], __obj = nil;
2221
2322
=== removed file 'utilities/SFHFKeychainUtils.h'
--- utilities/SFHFKeychainUtils.h 2010-09-20 20:32:15 +0000
+++ utilities/SFHFKeychainUtils.h 1970-01-01 00:00:00 +0000
@@ -1,41 +0,0 @@
1//
2// SFHFKeychainUtils.h
3//
4// Created by Buzz Andersen on 10/20/08.
5// Based partly on code by Jonathan Wight, Jon Crosby, and Mike Malone.
6// Copyright 2008 Sci-Fi Hi-Fi. All rights reserved.
7//
8// Permission is hereby granted, free of charge, to any person
9// obtaining a copy of this software and associated documentation
10// files (the "Software"), to deal in the Software without
11// restriction, including without limitation the rights to use,
12// copy, modify, merge, publish, distribute, sublicense, and/or sell
13// copies of the Software, and to permit persons to whom the
14// Software is furnished to do so, subject to the following
15// conditions:
16//
17// The above copyright notice and this permission notice shall be
18// included in all copies or substantial portions of the Software.
19//
20// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27// OTHER DEALINGS IN THE SOFTWARE.
28//
29
30#import <UIKit/UIKit.h>
31
32
33@interface SFHFKeychainUtils : NSObject {
34
35}
36
37+ (NSString *) getPasswordForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error;
38+ (BOOL) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error;
39+ (BOOL) deleteItemForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error;
40
41@end
42\ No newline at end of file0\ No newline at end of file
431
=== removed file 'utilities/SFHFKeychainUtils.m'
--- utilities/SFHFKeychainUtils.m 2010-09-24 05:34:15 +0000
+++ utilities/SFHFKeychainUtils.m 1970-01-01 00:00:00 +0000
@@ -1,272 +0,0 @@
1//
2// SFHFKeychainUtils.m
3//
4// Created by Buzz Andersen on 10/20/08.
5// Based partly on code by Jonathan Wight, Jon Crosby, and Mike Malone.
6// Copyright 2008 Sci-Fi Hi-Fi. All rights reserved.
7//
8// Permission is hereby granted, free of charge, to any person
9// obtaining a copy of this software and associated documentation
10// files (the "Software"), to deal in the Software without
11// restriction, including without limitation the rights to use,
12// copy, modify, merge, publish, distribute, sublicense, and/or sell
13// copies of the Software, and to permit persons to whom the
14// Software is furnished to do so, subject to the following
15// conditions:
16//
17// The above copyright notice and this permission notice shall be
18// included in all copies or substantial portions of the Software.
19//
20// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27// OTHER DEALINGS IN THE SOFTWARE.
28//
29
30#import "SFHFKeychainUtils.h"
31#import <Security/Security.h>
32
33static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
34
35@implementation SFHFKeychainUtils
36
37
38+ (NSString *) getPasswordForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error {
39 if (!username || !serviceName) {
40 if (error != nil) {
41 *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -2000 userInfo: nil];
42 }
43 return nil;
44 }
45
46 if (error != nil) {
47 *error = nil;
48 }
49
50 // Set up a query dictionary with the base query attributes: item type (generic), username, and service
51
52 NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass, kSecAttrAccount, kSecAttrService, nil] autorelease];
53 NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword, username, serviceName, nil] autorelease];
54
55 NSMutableDictionary *query = [[[NSMutableDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
56
57 // First do a query for attributes, in case we already have a Keychain item with no password data set.
58 // One likely way such an incorrect item could have come about is due to the previous (incorrect)
59 // version of this code (which set the password as a generic attribute instead of password data).
60
61 NSDictionary *attributeResult = NULL;
62 NSMutableDictionary *attributeQuery = [query mutableCopy];
63 [attributeQuery setObject: (id) kCFBooleanTrue forKey:(id) kSecReturnAttributes];
64 OSStatus status = SecItemCopyMatching((CFDictionaryRef) attributeQuery, (CFTypeRef *) &attributeResult);
65
66 [attributeResult release];
67 [attributeQuery release];
68
69 if (status != noErr) {
70 // No existing item found--simply return nil for the password
71 if (error != nil && status != errSecItemNotFound) {
72 //Only return an error if a real exception happened--not simply for "not found."
73 *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
74 }
75
76 return nil;
77 }
78
79 // We have an existing item, now query for the password data associated with it.
80
81 NSData *resultData = nil;
82 NSMutableDictionary *passwordQuery = [query mutableCopy];
83 [passwordQuery setObject: (id) kCFBooleanTrue forKey: (id) kSecReturnData];
84
85 status = SecItemCopyMatching((CFDictionaryRef) passwordQuery, (CFTypeRef *) &resultData);
86
87 [resultData autorelease];
88 [passwordQuery release];
89
90 if (status != noErr) {
91 if (status == errSecItemNotFound) {
92 // We found attributes for the item previously, but no password now, so return a special error.
93 // Users of this API will probably want to detect this error and prompt the user to
94 // re-enter their credentials. When you attempt to store the re-entered credentials
95 // using storeUsername:andPassword:forServiceName:updateExisting:error
96 // the old, incorrect entry will be deleted and a new one with a properly encrypted
97 // password will be added.
98 if (error != nil) {
99 *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -1999 userInfo: nil];
100 }
101 }
102 else {
103 // Something else went wrong. Simply return the normal Keychain API error code.
104 if (error != nil) {
105 *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
106 }
107 }
108
109 return nil;
110 }
111
112 NSString *password = nil;
113
114 if (resultData) {
115 password = [[NSString alloc] initWithData: resultData encoding: NSUTF8StringEncoding];
116 }
117 else {
118 // There is an existing item, but we weren't able to get password data for it for some reason,
119 // Possibly as a result of an item being incorrectly entered by the previous code.
120 // Set the -1999 error so the code above us can prompt the user again.
121 if (error != nil) {
122 *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -1999 userInfo: nil];
123 }
124 }
125
126 return [password autorelease];
127}
128
129+ (BOOL) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error
130{
131 if (!username || !password || !serviceName)
132 {
133 if (error != nil)
134 {
135 *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -2000 userInfo: nil];
136 }
137 return NO;
138 }
139
140 // See if we already have a password entered for these credentials.
141 NSError *getError = nil;
142 NSString *existingPassword = [SFHFKeychainUtils getPasswordForUsername: username andServiceName: serviceName error:&getError];
143
144 if ([getError code] == -1999)
145 {
146 // There is an existing entry without a password properly stored (possibly as a result of the previous incorrect version of this code.
147 // Delete the existing item before moving on entering a correct one.
148
149 getError = nil;
150
151 [self deleteItemForUsername: username andServiceName: serviceName error: &getError];
152
153 if ([getError code] != noErr)
154 {
155 if (error != nil)
156 {
157 *error = getError;
158 }
159 return NO;
160 }
161 }
162 else if ([getError code] != noErr)
163 {
164 if (error != nil)
165 {
166 *error = getError;
167 }
168 return NO;
169 }
170
171 if (error != nil)
172 {
173 *error = nil;
174 }
175
176 OSStatus status = noErr;
177
178 if (existingPassword)
179 {
180 // We have an existing, properly entered item with a password.
181 // Update the existing item.
182
183 if (![existingPassword isEqualToString:password] && updateExisting)
184 {
185 //Only update if we're allowed to update existing. If not, simply do nothing.
186
187 NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass,
188 kSecAttrService,
189 kSecAttrLabel,
190 kSecAttrAccount,
191 nil] autorelease];
192
193 NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword,
194 serviceName,
195 serviceName,
196 username,
197 nil] autorelease];
198
199 NSDictionary *query = [[[NSDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
200
201 status = SecItemUpdate((CFDictionaryRef) query, (CFDictionaryRef) [NSDictionary dictionaryWithObject: [password dataUsingEncoding: NSUTF8StringEncoding] forKey: (NSString *) kSecValueData]);
202 }
203 }
204 else
205 {
206 // No existing entry (or an existing, improperly entered, and therefore now
207 // deleted, entry). Create a new entry.
208
209 NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass,
210 kSecAttrService,
211 kSecAttrLabel,
212 kSecAttrAccount,
213 kSecValueData,
214 nil] autorelease];
215
216 NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword,
217 serviceName,
218 serviceName,
219 username,
220 [password dataUsingEncoding: NSUTF8StringEncoding],
221 nil] autorelease];
222
223 NSDictionary *query = [[[NSDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
224
225 status = SecItemAdd((CFDictionaryRef) query, NULL);
226 }
227
228 if (error != nil && status != noErr)
229 {
230 // Something went wrong with adding the new item. Return the Keychain error code.
231 *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
232
233 return NO;
234 }
235
236 return YES;
237}
238
239+ (BOOL) deleteItemForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error
240{
241 if (!username || !serviceName)
242 {
243 if (error != nil)
244 {
245 *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -2000 userInfo: nil];
246 }
247 return NO;
248 }
249
250 if (error != nil)
251 {
252 *error = nil;
253 }
254
255 NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass, kSecAttrAccount, kSecAttrService, kSecReturnAttributes, nil] autorelease];
256 NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword, username, serviceName, kCFBooleanTrue, nil] autorelease];
257
258 NSDictionary *query = [[[NSDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
259
260 OSStatus status = SecItemDelete((CFDictionaryRef) query);
261
262 if (error != nil && status != noErr)
263 {
264 *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
265
266 return NO;
267 }
268
269 return YES;
270}
271
272@end
273\ No newline at end of file0\ No newline at end of file
2741
=== modified file 'utilities/Subsonic.h'
--- utilities/Subsonic.h 2011-11-05 00:42:21 +0000
+++ utilities/Subsonic.h 2012-09-25 21:30:30 +0000
@@ -47,5 +47,4 @@
47- (NSURL *)getStreamingURLForSongId:(NSString*)songId;47- (NSURL *)getStreamingURLForSongId:(NSString*)songId;
48- (NSURL *)buildURLWithBase:(NSString *)baseURL action:(NSString *)action parameters:(NSArray *)extraParameters;48- (NSURL *)buildURLWithBase:(NSString *)baseURL action:(NSString *)action parameters:(NSArray *)extraParameters;
49- (void)removeCredentials;49- (void)removeCredentials;
50- (void)storeUsername:(NSString*)username password:(NSString*)password;
51@end50@end
5251
=== modified file 'utilities/Subsonic.m'
--- utilities/Subsonic.m 2011-11-05 00:42:21 +0000
+++ utilities/Subsonic.m 2012-09-25 21:30:30 +0000
@@ -24,6 +24,7 @@
24#include <arpa/inet.h>24#include <arpa/inet.h>
25#import "NSMutableArray+Extras.h"25#import "NSMutableArray+Extras.h"
26#import "Reachability.h"26#import "Reachability.h"
27#import "UOAuthManager.h"
2728
28@interface Subsonic ()29@interface Subsonic ()
29@property (readwrite, retain) Reachability *reachability;30@property (readwrite, retain) Reachability *reachability;
@@ -62,10 +63,10 @@
6263
63- (BOOL)hasCredentials64- (BOOL)hasCredentials
64{65{
65 NSString *username = [SFHFKeychainUtils getPasswordForUsername:UBUNTU_ONE_DUMMY_USER_NAME andServiceName:UBUNTU_ONE_SERVICE_NAME error:nil];66 NSString *username = [[UOAuthManager sharedAuthManager] subsonicUsername];
66 if (username)67 if (username)
67 {68 {
68 NSString *password = [SFHFKeychainUtils getPasswordForUsername:username andServiceName:UBUNTU_ONE_SERVICE_NAME error:nil];69 NSString *password = [[UOAuthManager sharedAuthManager] subsonicPassword];
69 return (password != nil);70 return (password != nil);
70 }71 }
71 else72 else
@@ -76,24 +77,7 @@
7677
77- (void)removeCredentials78- (void)removeCredentials
78{79{
79 NSString *username = [[SFHFKeychainUtils getPasswordForUsername:UBUNTU_ONE_DUMMY_USER_NAME andServiceName:UBUNTU_ONE_SERVICE_NAME error:nil] retain];80 [[UOAuthManager sharedAuthManager] clearSubsonicCredentials];
80
81 if (username)
82 {
83 [SFHFKeychainUtils deleteItemForUsername:UBUNTU_ONE_DUMMY_USER_NAME andServiceName:UBUNTU_ONE_SERVICE_NAME error:nil];
84 [SFHFKeychainUtils deleteItemForUsername:username andServiceName:UBUNTU_ONE_SERVICE_NAME error:nil];
85 }
86
87 [username release];
88}
89
90- (void)storeUsername:(NSString*)username password:(NSString*)password
91{
92 [SFHFKeychainUtils storeUsername:UBUNTU_ONE_DUMMY_USER_NAME andPassword:username forServiceName:UBUNTU_ONE_SERVICE_NAME updateExisting:YES error:nil];
93 [SFHFKeychainUtils storeUsername:username andPassword:password forServiceName:UBUNTU_ONE_SERVICE_NAME updateExisting:YES error:nil];
94
95 self.defaultUserName = username;
96 self.defaultPassword = password;
97}81}
9882
99- (NSURL *)getStreamingURLForSongId:(NSString*)songId83- (NSURL *)getStreamingURLForSongId:(NSString*)songId

Subscribers

People subscribed via source and target branches