#include "configd.h"
#include "session.h"
__private_extern__
int
__SCDynamicStoreAddValue(SCDynamicStoreRef store, CFStringRef key, CFDataRef value, Boolean internal)
{
SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
int sc_status = kSCStatusOK;
CFDataRef tempValue;
if (!store || (storePrivate->server == MACH_PORT_NULL)) {
return kSCStatusNoStoreSession;
}
if (_configd_trace) {
SCTrace(TRUE, _configd_trace,
CFSTR("%s%s : %5d : %@\n"),
internal ? "*add " : "add ",
storePrivate->useSessionKeys ? "t " : " ",
storePrivate->server,
key);
}
sc_status = __SCDynamicStoreLock(store, TRUE);
if (sc_status != kSCStatusOK) {
return sc_status;
}
sc_status = __SCDynamicStoreCopyValue(store, key, &tempValue, TRUE);
switch (sc_status) {
case kSCStatusNoKey :
break;
case kSCStatusOK :
CFRelease(tempValue);
sc_status = kSCStatusKeyExists;
goto done;
default :
#ifdef DEBUG
SCLog(_configd_verbose, LOG_DEBUG, CFSTR("__SCDynamicStoreAddValue __SCDynamicStoreCopyValue(): %s"), SCErrorString(sc_status));
#endif
goto done;
}
sc_status = __SCDynamicStoreSetValue(store, key, value, TRUE);
done:
__SCDynamicStoreUnlock(store, TRUE);
return sc_status;
}
__private_extern__
kern_return_t
_configadd(mach_port_t server,
xmlData_t keyRef,
mach_msg_type_number_t keyLen,
xmlData_t dataRef,
mach_msg_type_number_t dataLen,
int *newInstance,
int *sc_status
)
{
CFStringRef key = NULL;
CFDataRef data = NULL;
serverSessionRef mySession = getSession(server);
if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
*sc_status = kSCStatusFailed;
goto done;
}
if (!isA_CFString(key)) {
*sc_status = kSCStatusInvalidArgument;
goto done;
}
if (!_SCUnserializeData(&data, (void *)dataRef, dataLen)) {
*sc_status = kSCStatusFailed;
goto done;
}
if (!mySession) {
*sc_status = kSCStatusNoStoreSession;
goto done;
}
*sc_status = __SCDynamicStoreAddValue(mySession->store, key, data, FALSE);
if (*sc_status == kSCStatusOK) {
*newInstance = 0;
}
done :
if (key) CFRelease(key);
if (data) CFRelease(data);
return KERN_SUCCESS;
}
__private_extern__
kern_return_t
_configadd_s(mach_port_t server,
xmlData_t keyRef,
mach_msg_type_number_t keyLen,
xmlData_t dataRef,
mach_msg_type_number_t dataLen,
int *newInstance,
int *sc_status
)
{
CFDataRef data = NULL;
CFStringRef key = NULL;
serverSessionRef mySession = getSession(server);
SCDynamicStorePrivateRef storePrivate;
Boolean useSessionKeys;
if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
*sc_status = kSCStatusFailed;
goto done;
}
if (!isA_CFString(key)) {
*sc_status = kSCStatusInvalidArgument;
goto done;
}
if (!_SCUnserializeData(&data, (void *)dataRef, dataLen)) {
*sc_status = kSCStatusFailed;
goto done;
}
if (!mySession) {
*sc_status = kSCStatusNoStoreSession;
goto done;
}
storePrivate = (SCDynamicStorePrivateRef)mySession->store;
useSessionKeys = storePrivate->useSessionKeys;
storePrivate->useSessionKeys = TRUE;
*sc_status = __SCDynamicStoreAddValue(mySession->store, key, data, FALSE);
if (*sc_status == kSCStatusOK) {
*newInstance = 0;
}
storePrivate->useSessionKeys = useSessionKeys;
done :
if (key) CFRelease(key);
if (data) CFRelease(data);
return KERN_SUCCESS;
}