#include <mach/mach.h>
#include <mach/mach_error.h>
#include <SystemConfiguration/SCD.h>
#include "config.h"
#include "SCDPrivate.h"
SCDStatus
SCDSet(SCDSessionRef session, CFStringRef key, SCDHandleRef handle)
{
SCDSessionPrivateRef sessionPrivate = (SCDSessionPrivateRef)session;
kern_return_t status;
CFDataRef xmlKey;
xmlData_t myKeyRef;
CFIndex myKeyLen;
CFDataRef xmlData;
xmlData_t myDataRef;
CFIndex myDataLen;
SCDStatus scd_status;
int newInstance;
SCDLog(LOG_DEBUG, CFSTR("SCDSet:"));
SCDLog(LOG_DEBUG, CFSTR(" key = %@"), key);
SCDLog(LOG_DEBUG, CFSTR(" data = %@"), SCDHandleGetData(handle));
SCDLog(LOG_DEBUG, CFSTR(" instance = %d"), SCDHandleGetInstance(handle));
if (key == NULL) {
return SCD_INVALIDARGUMENT;
}
if ((session == NULL) || (sessionPrivate->server == MACH_PORT_NULL)) {
return SCD_NOSESSION;
}
xmlKey = CFPropertyListCreateXMLData(NULL, key);
myKeyRef = (xmlData_t)CFDataGetBytePtr(xmlKey);
myKeyLen = CFDataGetLength(xmlKey);
xmlData = CFPropertyListCreateXMLData(NULL, SCDHandleGetData(handle));
myDataRef = (xmlData_t)CFDataGetBytePtr(xmlData);
myDataLen = CFDataGetLength(xmlData);
status = configset(sessionPrivate->server,
myKeyRef,
myKeyLen,
myDataRef,
myDataLen,
SCDHandleGetInstance(handle),
&newInstance,
(int *)&scd_status);
CFRelease(xmlKey);
CFRelease(xmlData);
if (status != KERN_SUCCESS) {
if (status != MACH_SEND_INVALID_DEST)
SCDLog(LOG_DEBUG, CFSTR("configset(): %s"), mach_error_string(status));
(void) mach_port_destroy(mach_task_self(), sessionPrivate->server);
sessionPrivate->server = MACH_PORT_NULL;
return SCD_NOSERVER;
}
if (scd_status == SCD_OK) {
_SCDHandleSetInstance(handle, newInstance);
}
SCDLog(LOG_DEBUG, CFSTR(" new instance = %d"), SCDHandleGetInstance(handle));
return scd_status;
}