Merge branch 'master' of git://github.com/ksuther/MenuTunes
[MenuTunes.git] / PreferencesController.m
index 612faf9..2b1bbf8 100755 (executable)
@@ -20,7 +20,7 @@
 #import <ITKit/ITTSWBackgroundView.h>
 
 #define SENDER_STATE (([sender state] == NSOnState) ? YES : NO)
-#define AUDIOSCROBBLER_KEYCHAIN_SERVICE(user) [NSString stringWithFormat:@"Audioscrobbler: %@", user]
+#define AUDIOSCROBBLER_KEYCHAIN_SERVICE(user) [[NSString stringWithFormat:@"Audioscrobbler: %@", user] UTF8String]
 #define AUDIOSCROBBLER_KEYCHAIN_KIND "application password"
 
 /*************************************************************************/
@@ -84,8 +84,8 @@ static PreferencesController *prefs = nil;
        attributes[1].data = AUDIOSCROBBLER_KEYCHAIN_KIND;
        attributes[1].length = strlen(AUDIOSCROBBLER_KEYCHAIN_KIND);
        attributes[2].tag = kSecLabelItemAttr;
-       attributes[2].data = AUDIOSCROBBLER_KEYCHAIN_SERVICE(user);
-       attributes[2].length = [AUDIOSCROBBLER_KEYCHAIN_SERVICE(user) length];
+       attributes[2].data = (char *)AUDIOSCROBBLER_KEYCHAIN_SERVICE(user);
+       attributes[2].length = strlen(AUDIOSCROBBLER_KEYCHAIN_SERVICE(user));
        list.count = 3;
        list.attr = attributes;
 
@@ -131,8 +131,8 @@ static PreferencesController *prefs = nil;
        attributes[1].data = AUDIOSCROBBLER_KEYCHAIN_KIND;
        attributes[1].length = strlen(AUDIOSCROBBLER_KEYCHAIN_KIND);
        attributes[2].tag = kSecLabelItemAttr;
-       attributes[2].data = AUDIOSCROBBLER_KEYCHAIN_SERVICE(user);
-       attributes[2].length = [AUDIOSCROBBLER_KEYCHAIN_SERVICE(user) length];
+       attributes[2].data = (char *)AUDIOSCROBBLER_KEYCHAIN_SERVICE(user);
+       attributes[2].length = strlen(AUDIOSCROBBLER_KEYCHAIN_SERVICE(user));
        list.count = 3;
        list.attr = attributes;
 
@@ -183,16 +183,15 @@ static PreferencesController *prefs = nil;
                if (status != noErr) {
                        ITDebugLog(@"Audioscrobbler: Error getting keychain item password: %i", status);
                } else {
-                       NSLog(@"Audioscrobbler: password buffer: \"%s\" \"Length: %i\"", buffer, length);
-                       pass = [NSString stringWithUTF8String:buffer];
+                       pass = [[NSString alloc] initWithBytes:buffer length:length encoding:NSUTF8StringEncoding];
                }
                if (status != noErr) {
                        ITDebugLog(@"Audioscrobbler: Error deleting keychain item: %i", status);
                }
+               SecKeychainItemFreeContent(NULL, buffer);
                CFRelease(item);
        }
-       NSLog(@"Audioscrobbler: Retrieved password: \"%@\"", pass);
-       return pass;
+       return [pass autorelease];
 }
 
 /*************************************************************************/