SCDNotifierRemove.c [plain text]
#include <mach/mach.h>
#include <mach/mach_error.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <SystemConfiguration/SCPrivate.h>
#include "SCDynamicStoreInternal.h"
#include "config.h"
Boolean
SCDynamicStoreRemoveWatchedKey(SCDynamicStoreRef store, CFStringRef key, Boolean isRegex)
{
SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
kern_return_t status;
CFDataRef xmlKey;
xmlData_t myKeyRef;
CFIndex myKeyLen;
int sc_status;
SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreRemoveWatchedKey:"));
SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" key = %@"), key);
SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" isRegex = %s"), isRegex ? "TRUE" : "FALSE");
if (!store) {
_SCErrorSet(kSCStatusNoStoreSession);
return FALSE;
}
if (storePrivate->server == MACH_PORT_NULL) {
_SCErrorSet(kSCStatusNoStoreServer);
return FALSE;
}
if (isRegex) {
if (!CFSetContainsValue(storePrivate->reKeys, key)) {
_SCErrorSet(kSCStatusNoKey);
return FALSE;
}
CFSetRemoveValue(storePrivate->reKeys, key);
} else {
if (!CFSetContainsValue(storePrivate->keys, key)) {
_SCErrorSet(kSCStatusNoKey);
return FALSE;
}
CFSetRemoveValue(storePrivate->keys, key);
}
xmlKey = CFPropertyListCreateXMLData(NULL, key);
myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey);
myKeyLen = CFDataGetLength(xmlKey);
status = notifyremove(storePrivate->server,
myKeyRef,
myKeyLen,
isRegex,
(int *)&sc_status);
CFRelease(xmlKey);
if (status != KERN_SUCCESS) {
if (status != MACH_SEND_INVALID_DEST)
SCLog(_sc_verbose, LOG_DEBUG, CFSTR("notifyremove(): %s"), mach_error_string(status));
(void) mach_port_destroy(mach_task_self(), storePrivate->server);
storePrivate->server = MACH_PORT_NULL;
_SCErrorSet(status);
return FALSE;
}
if (sc_status != kSCStatusOK) {
_SCErrorSet(sc_status);
return FALSE;
}
return TRUE;
}