KCEventNotifier.cpp [plain text]
#include "KCEventNotifier.h"
#include "KCExceptions.h"
#include "Keychains.h"
using namespace KeychainCore;
void KCEventNotifier::PostKeychainEvent(SecKeychainEvent whichEvent, const Keychain &keychain, const Item &kcItem)
{
DLDbIdentifier dlDbIdentifier;
PrimaryKey primaryKey;
if (keychain)
dlDbIdentifier = keychain->dLDbIdentifier();
if (kcItem)
primaryKey = kcItem->primaryKey();
PostKeychainEvent(whichEvent, dlDbIdentifier, primaryKey);
}
void KCEventNotifier::PostKeychainEvent(SecKeychainEvent whichEvent,
const DLDbIdentifier &dlDbIdentifier,
const PrimaryKey &primaryKey)
{
CFRef<CFMutableDictionaryRef> mutableDict(::CFDictionaryCreateMutable(kCFAllocatorDefault,0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
KCThrowIfMemFail_(CFMutableDictionaryRef(mutableDict));
SInt32 theEvent = SInt32(whichEvent);
CFRef<CFNumberRef> theEventData(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &theEvent));
KCThrowIfMemFail_(CFNumberRef(theEventData));
CFDictionarySetValue(mutableDict, kSecEventTypeKey, theEventData);
if (dlDbIdentifier)
{
CFRef<CFDictionaryRef> dict(DLDbListCFPref::dlDbIdentifierToCFDictionaryRef(dlDbIdentifier));
KCThrowIfMemFail_(CFDictionaryRef(dict));
CFDictionarySetValue(mutableDict, kSecEventKeychainKey, dict);
}
if (primaryKey)
{
CFRef<CFDataRef> data(CFDataCreate(kCFAllocatorDefault, primaryKey->Data, primaryKey->Length));
KCThrowIfMemFail_(CFDataRef(data));
CFDictionarySetValue(mutableDict, kSecEventItemKey, data);
}
CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
kSecEventNotificationName, NULL, mutableDict, false);
}