+void
+DLDbListCFPref::remove(const DLDbIdentifier &dldbIdentifier)
+{
+ // Make sure mSearchList is set
+ searchList();
+ for (vector<DLDbIdentifier>::iterator ix = mSearchList.begin(); ix != mSearchList.end(); ++ix)
+ {
+ if (*ix==dldbIdentifier) // found in list
+ {
+ mSearchList.erase(ix);
+ changed(true);
+ break;
+ }
+ }
+}
+
+const vector<DLDbIdentifier> &
+DLDbListCFPref::searchList()
+{
+ if (!mSearchListSet)
+ {
+ CFArrayRef searchList = reinterpret_cast<CFArrayRef>(CFDictionaryGetValue(mPropertyList, kDefaultDLDbListKey));
+ if (searchList && CFGetTypeID(searchList) != CFArrayGetTypeID())
+ searchList = NULL;
+
+ if (searchList)
+ {
+ CFIndex top = CFArrayGetCount(searchList);
+ // Each entry is a CFDictionary; peel it off & add it to the array
+ for (CFIndex idx = 0; idx < top; ++idx)
+ {
+ CFDictionaryRef theDict = reinterpret_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(searchList, idx));
+ try
+ {
+ mSearchList.push_back(cfDictionaryRefToDLDbIdentifier(theDict));
+ }
+ catch (...)
+ {
+ // Drop stuff that doesn't parse on the floor.
+ }
+ }
+
+ // If there were entries specified, but they were invalid revert to using the
+ // default keychain in the searchlist.
+ if (top > 0 && mSearchList.size() == 0)
+ searchList = NULL;
+ }
+
+ // The default when no search list is specified is to only search the
+ // default keychain.
+ if (!searchList && static_cast<bool>(defaultDLDbIdentifier()))
+ mSearchList.push_back(mDefaultDLDbIdentifier);
+
+ mSearchListSet = true;
+ }
+
+ return mSearchList;
+}
+
+void
+DLDbListCFPref::searchList(const vector<DLDbIdentifier> &searchList)
+{
+ vector<DLDbIdentifier> newList(searchList);
+ mSearchList.swap(newList);
+ mSearchListSet = true;
+ changed(true);
+}
+
+void
+DLDbListCFPref::defaultDLDbIdentifier(const DLDbIdentifier &dlDbIdentifier)
+{
+ if (!(defaultDLDbIdentifier() == dlDbIdentifier))
+ {
+ mDefaultDLDbIdentifier = dlDbIdentifier;
+ changed(true);
+ }
+}
+
+const DLDbIdentifier &
+DLDbListCFPref::defaultDLDbIdentifier()
+{
+ if (!mDefaultDLDbIdentifierSet)
+ {
+ CFArrayRef defaultArray = reinterpret_cast<CFArrayRef>(CFDictionaryGetValue(mPropertyList, kDefaultKeychainKey));
+ if (defaultArray && CFGetTypeID(defaultArray) != CFArrayGetTypeID())
+ defaultArray = NULL;
+
+ if (defaultArray && CFArrayGetCount(defaultArray) > 0)
+ {
+ CFDictionaryRef defaultDict = reinterpret_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(defaultArray, 0));
+ try
+ {
+ x_debug("Getting default DLDbIdentifier from defaultDict");
+ mDefaultDLDbIdentifier = cfDictionaryRefToDLDbIdentifier(defaultDict);
+ x_debug1("Now we think the default keychain is %s", (mDefaultDLDbIdentifier) ? mDefaultDLDbIdentifier.dbName() : "<NULL>");
+ }
+ catch (...)
+ {
+ // If defaultArray doesn't parse fall back on the default way of getting the default keychain
+ defaultArray = NULL;
+ }
+ }
+
+ if (!defaultArray)
+ {
+ // If the Panther style login keychain actually exists we use that otherwise no
+ // default is set.
+ mDefaultDLDbIdentifier = loginDLDbIdentifier();
+ x_debug1("Now we think the default keychain is %s", (mDefaultDLDbIdentifier) ? mDefaultDLDbIdentifier.dbName() : "<NULL>");
+
+ struct stat st;
+ int st_result = stat(mDefaultDLDbIdentifier.dbName(), &st);
+ if (st_result)
+ {
+ x_debug2("stat() of %s returned %d", mDefaultDLDbIdentifier.dbName(), st_result);
+ mDefaultDLDbIdentifier = DLDbIdentifier();
+ x_debug1("After DLDbIdentifier(), we think the default keychain is %s", static_cast<bool>(mDefaultDLDbIdentifier) ? mDefaultDLDbIdentifier.dbName() : "<NULL>");
+ }
+ }
+
+ mDefaultDLDbIdentifierSet = true;
+ }
+
+ return mDefaultDLDbIdentifier;
+}
+
+void
+DLDbListCFPref::loginDLDbIdentifier(const DLDbIdentifier &dlDbIdentifier)
+{
+ if (!(loginDLDbIdentifier() == dlDbIdentifier))
+ {
+ mLoginDLDbIdentifier = dlDbIdentifier;
+ changed(true);
+ }
+}
+
+const DLDbIdentifier &
+DLDbListCFPref::loginDLDbIdentifier()
+{
+ if (!mLoginDLDbIdentifierSet)
+ {
+ CFArrayRef loginArray = reinterpret_cast<CFArrayRef>(CFDictionaryGetValue(mPropertyList, kLoginKeychainKey));
+ if (loginArray && CFGetTypeID(loginArray) != CFArrayGetTypeID())
+ loginArray = NULL;
+
+ if (loginArray && CFArrayGetCount(loginArray) > 0)
+ {
+ CFDictionaryRef loginDict = reinterpret_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(loginArray, 0));
+ try
+ {
+ x_debug("Getting login DLDbIdentifier from loginDict");
+ mLoginDLDbIdentifier = cfDictionaryRefToDLDbIdentifier(loginDict);
+ x_debug1("We think the login keychain is %s", static_cast<bool>(mLoginDLDbIdentifier) ? mLoginDLDbIdentifier.dbName() : "<NULL>");
+ }
+ catch (...)
+ {
+ // If loginArray doesn't parse fall back on the default way of getting the login keychain.
+ loginArray = NULL;
+ }
+ }
+
+ if (!loginArray)
+ {
+ // If the jaguar login keychain actually exists we use that otherwise no
+ // login keychain is set.
+ x_debug("No loginDict found, calling JaguarLoginDLDbIdentifier()");
+ mLoginDLDbIdentifier = JaguarLoginDLDbIdentifier();
+ x_debug1("After JaguarLoginDLDbIdentifier(), we think the login keychain is %s", static_cast<bool>(mLoginDLDbIdentifier) ? mLoginDLDbIdentifier.dbName() : "<NULL>");
+
+ struct stat st;
+ int st_result = stat(mLoginDLDbIdentifier.dbName(), &st);
+ if (st_result)
+ {
+ // Jaguar login Keychain didn't exist, so assume new style one.
+ x_debug2("stat() of %s returned %d", mLoginDLDbIdentifier.dbName(), st_result);
+ mLoginDLDbIdentifier = LoginDLDbIdentifier();
+ x_debug1("After LoginDLDbIdentifier(), we think the login keychain is %s", static_cast<bool>(mLoginDLDbIdentifier) ? mLoginDLDbIdentifier.dbName() : "<NULL>");
+ }
+ }
+
+ mLoginDLDbIdentifierSet = true;
+ }
+
+ return mLoginDLDbIdentifier;
+}