#include <mach/mach.h>
#include <mach/mach_error.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <SystemConfiguration/SCPrivate.h>
#include "SCDynamicStoreInternal.h"
#include "config.h"
Boolean
SCDynamicStoreAddValue(SCDynamicStoreRef store, CFStringRef key, CFPropertyListRef value)
{
SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
kern_return_t status;
CFDataRef utfKey;
xmlData_t myKeyRef;
CFIndex myKeyLen;
CFDataRef xmlData;
xmlData_t myDataRef;
CFIndex myDataLen;
int newInstance;
int sc_status;
if (_sc_verbose) {
SCLog(TRUE, LOG_DEBUG, CFSTR("SCDynamicStoreAddValue:"));
SCLog(TRUE, LOG_DEBUG, CFSTR(" key = %@"), key);
SCLog(TRUE, LOG_DEBUG, CFSTR(" value = %@"), value);
}
if (!store) {
_SCErrorSet(kSCStatusNoStoreSession);
return FALSE;
}
if (storePrivate->server == MACH_PORT_NULL) {
_SCErrorSet(kSCStatusNoStoreServer);
return FALSE;
}
if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) {
_SCErrorSet(kSCStatusFailed);
return FALSE;
}
if (!_SCSerialize(value, &xmlData, (void **)&myDataRef, &myDataLen)) {
CFRelease(utfKey);
_SCErrorSet(kSCStatusFailed);
return FALSE;
}
status = configadd(storePrivate->server,
myKeyRef,
myKeyLen,
myDataRef,
myDataLen,
&newInstance,
(int *)&sc_status);
CFRelease(utfKey);
CFRelease(xmlData);
if (status != KERN_SUCCESS) {
if (status != MACH_SEND_INVALID_DEST)
SCLog(_sc_verbose, LOG_DEBUG, CFSTR("configadd(): %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;
}