#include "SCDynamicStoreInternal.h"
#include "config.h"
Boolean
SCDynamicStoreRemoveValue(SCDynamicStoreRef store, CFStringRef key)
{
SCDynamicStorePrivateRef storePrivate;
kern_return_t status;
CFDataRef utfKey;
xmlData_t myKeyRef;
CFIndex myKeyLen;
int sc_status;
if (store == NULL) {
store = __SCDynamicStoreNullSession();
if (store == NULL) {
_SCErrorSet(kSCStatusNoStoreSession);
return FALSE;
}
}
storePrivate = (SCDynamicStorePrivateRef)store;
if (storePrivate->server == MACH_PORT_NULL) {
_SCErrorSet(kSCStatusNoStoreServer);
return FALSE;
}
if (storePrivate->cache_active) {
if (storePrivate->cached_set != NULL) {
CFDictionaryRemoveValue(storePrivate->cached_set, key);
}
if (storePrivate->cached_removals == NULL) {
storePrivate->cached_removals = CFArrayCreateMutable(NULL,
0,
&kCFTypeArrayCallBacks);
}
if (!CFArrayContainsValue(storePrivate->cached_removals,
CFRangeMake(0, CFArrayGetCount(storePrivate->cached_removals)),
key)) {
CFArrayAppendValue(storePrivate->cached_removals, key);
}
return TRUE;
}
if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) {
_SCErrorSet(kSCStatusFailed);
return FALSE;
}
retry :
status = configremove(storePrivate->server,
myKeyRef,
(mach_msg_type_number_t)myKeyLen,
(int *)&sc_status);
if (__SCDynamicStoreCheckRetryAndHandleError(store,
status,
&sc_status,
"SCDynamicStoreRemoveValue configremove()")) {
goto retry;
}
CFRelease(utfKey);
if (sc_status != kSCStatusOK) {
_SCErrorSet(sc_status);
return FALSE;
}
return TRUE;
}