#include <mach/mach.h>
#include <mach/mach_error.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <SystemConfiguration/SCPrivate.h>
#include "SCDynamicStoreInternal.h"
#include "config.h"
Boolean
SCDynamicStoreAddTemporaryValue(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 (store == NULL) {
_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_s(storePrivate->server,
myKeyRef,
myKeyLen,
myDataRef,
myDataLen,
&newInstance,
(int *)&sc_status);
CFRelease(utfKey);
CFRelease(xmlData);
if (status != KERN_SUCCESS) {
if (status == MACH_SEND_INVALID_DEST) {
(void) mach_port_deallocate(mach_task_self(), storePrivate->server);
} else {
SCLog(TRUE, LOG_ERR, CFSTR("SCDynamicStoreAddTemporaryValue configadd_s(): %s"), mach_error_string(status));
}
storePrivate->server = MACH_PORT_NULL;
_SCErrorSet(status);
return FALSE;
}
if (sc_status != kSCStatusOK) {
_SCErrorSet(sc_status);
return FALSE;
}
return TRUE;
}
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 (store == NULL) {
_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) {
(void) mach_port_deallocate(mach_task_self(), storePrivate->server);
} else {
SCLog(TRUE, LOG_ERR, CFSTR("SCDynamicStoreAddValue configadd(): %s"), mach_error_string(status));
}
storePrivate->server = MACH_PORT_NULL;
_SCErrorSet(status);
return FALSE;
}
if (sc_status != kSCStatusOK) {
_SCErrorSet(sc_status);
return FALSE;
}
return TRUE;
}