#include "configd.h"
#include "session.h"
int
__SCDynamicStoreNotifyValue(SCDynamicStoreRef store, CFStringRef key)
{
SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
int sc_status = kSCStatusOK;
CFDictionaryRef dict;
Boolean newValue = FALSE;
CFPropertyListRef value;
SCLog(_configd_verbose, LOG_DEBUG, CFSTR("__SCDynamicStoreNotifyValue:"));
SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" key = %@"), key);
if (!store || (storePrivate->server == MACH_PORT_NULL)) {
return kSCStatusNoStoreSession;
}
sc_status = __SCDynamicStoreLock(store, TRUE);
if (sc_status != kSCStatusOK) {
return sc_status;
}
dict = CFDictionaryGetValue(storeData, key);
if (!dict || !CFDictionaryGetValueIfPresent(dict, kSCDData, (const void **)&value)) {
value = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
newValue = TRUE;
}
__SCDynamicStoreSetValue(store, key, value);
if (newValue) {
__SCDynamicStoreRemoveValue(store, key);
CFRelease(value);
}
__SCDynamicStoreUnlock(store, TRUE);
return sc_status;
}
kern_return_t
_confignotify(mach_port_t server,
xmlData_t keyRef,
mach_msg_type_number_t keyLen,
int *sc_status
)
{
serverSessionRef mySession = getSession(server);
CFStringRef key;
SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Notify key in configuration database."));
SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server);
if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
*sc_status = kSCStatusFailed;
return KERN_SUCCESS;
}
if (!isA_CFString(key)) {
CFRelease(key);
*sc_status = kSCStatusInvalidArgument;
return KERN_SUCCESS;
}
*sc_status = __SCDynamicStoreNotifyValue(mySession->store, key);
CFRelease(key);
return KERN_SUCCESS;
}