On MacRuby Pointer to typedef struct, I learnt how to dereference a pointer created with
x=Pointer.new_with_type
...
==> use x.value, or x[0]
Works a treat !
Now I want to learn what I believe to be the "opposite". I'm trying to use this API.
OSStatus SecKeychainCopySettings (
SecKeychainRef keychain,
SecKeychainSettings *outSettings
);
Second parameter must be a Pointer. But I never manage to get the real outSettings of the keychain opened, I only get the default settings.
framework 'Security'
keychainObject = Pointer.new_with_type('^{OpaqueSecKeychainRef}')
SecKeychainOpen("/Users/charbon/Library/Keychains/Josja.keychain",keychainObject)
#attempt #1
settings=Pointer.new_with_type('{SecKeychainSettings=IBBI}')
SecKeychainCopySettings(keychainObject.value, settings)
p settings.value
#<SecKeychainSettings version=0 lockOnSleep=false useLockInterval=false lockInterval=0>
#attempt #2
settings2=SecKeychainSettings.new
result = SecKeychainCopySettings(keychainObject.value, settings2)
p settings2
#<SecKeychainSettings version=0 lockOnSleep=false useLockInterval=false lockInterval=0>
The settings of the Keychain opened should read
#<SecKeychainSettings version=0 lockOnSleep=true useLockInterval=true lockInterval=1800>
What am I missing ?
Got it ! The doc to SecKeychainCopySettings mentions
So we can't just create a Pointer to SecKeychainSettings. We must set the version of the Struct that is pointed by the pointer to to something.