2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * Modification History
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
29 * March 24, 2000 Allan Nathanson <ajn@apple.com>
33 #include <mach/mach.h>
34 #include <mach/mach_error.h>
36 #include <SystemConfiguration/SystemConfiguration.h>
37 #include <SystemConfiguration/SCPrivate.h>
38 #include "SCDynamicStoreInternal.h"
39 #include "config.h" /* MiG generated file */
42 SCDynamicStoreSetMultiple(SCDynamicStoreRef store
,
43 CFDictionaryRef keysToSet
,
44 CFArrayRef keysToRemove
,
45 CFArrayRef keysToNotify
)
47 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
49 CFDataRef xmlSet
= NULL
; /* key/value pairs to set (XML serialized) */
50 xmlData_t mySetRef
= NULL
; /* key/value pairs to set (serialized) */
52 CFDataRef xmlRemove
= NULL
; /* keys to remove (XML serialized) */
53 xmlData_t myRemoveRef
= NULL
; /* keys to remove (serialized) */
54 CFIndex myRemoveLen
= 0;
55 CFDataRef xmlNotify
= NULL
; /* keys to notify (XML serialized) */
56 xmlData_t myNotifyRef
= NULL
; /* keys to notify (serialized) */
57 CFIndex myNotifyLen
= 0;
60 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("SCDynamicStoreSetMultiple:"));
61 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" keysToSet = %@"), keysToSet
);
62 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" keysToRemove = %@"), keysToRemove
);
63 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" keysToNotify = %@"), keysToNotify
);
66 /* sorry, you must provide a session */
67 _SCErrorSet(kSCStatusNoStoreSession
);
71 if (storePrivate
->server
== MACH_PORT_NULL
) {
72 _SCErrorSet(kSCStatusNoStoreServer
);
73 return NULL
; /* you must have an open session to play */
76 /* serialize the key/value pairs to set*/
78 xmlSet
= CFPropertyListCreateXMLData(NULL
, keysToSet
);
79 mySetRef
= (xmlData_t
)CFDataGetBytePtr(xmlSet
);
80 mySetLen
= CFDataGetLength(xmlSet
);
83 /* serialize the keys to remove */
85 xmlRemove
= CFPropertyListCreateXMLData(NULL
, keysToRemove
);
86 myRemoveRef
= (xmlData_t
)CFDataGetBytePtr(xmlRemove
);
87 myRemoveLen
= CFDataGetLength(xmlRemove
);
90 /* serialize the keys to notify */
92 xmlNotify
= CFPropertyListCreateXMLData(NULL
, keysToNotify
);
93 myNotifyRef
= (xmlData_t
)CFDataGetBytePtr(xmlNotify
);
94 myNotifyLen
= CFDataGetLength(xmlNotify
);
97 /* send the keys and patterns, fetch the associated result from the server */
98 status
= configset_m(storePrivate
->server
,
108 if (xmlSet
) CFRelease(xmlSet
);
109 if (xmlRemove
) CFRelease(xmlRemove
);
110 if (xmlNotify
) CFRelease(xmlNotify
);
112 if (status
!= KERN_SUCCESS
) {
113 if (status
!= MACH_SEND_INVALID_DEST
)
114 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configset_m(): %s"), mach_error_string(status
));
115 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
116 storePrivate
->server
= MACH_PORT_NULL
;
121 if (sc_status
!= kSCStatusOK
) {
122 _SCErrorSet(sc_status
);
130 SCDynamicStoreSetValue(SCDynamicStoreRef store
, CFStringRef key
, CFPropertyListRef value
)
132 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
133 kern_return_t status
;
134 CFDataRef xmlKey
; /* serialized key */
137 CFDataRef xmlData
; /* serialized data */
143 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("SCDynamicStoreSetValue:"));
144 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
145 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" value = %@"), value
);
148 /* sorry, you must provide a session */
149 _SCErrorSet(kSCStatusNoStoreSession
);
153 if (storePrivate
->server
== MACH_PORT_NULL
) {
154 /* sorry, you must have an open session to play */
155 _SCErrorSet(kSCStatusNoStoreServer
);
159 /* serialize the key and data */
160 xmlKey
= CFPropertyListCreateXMLData(NULL
, key
);
161 myKeyRef
= (xmlData_t
)CFDataGetBytePtr(xmlKey
);
162 myKeyLen
= CFDataGetLength(xmlKey
);
164 xmlData
= CFPropertyListCreateXMLData(NULL
, value
);
165 myDataRef
= (xmlData_t
)CFDataGetBytePtr(xmlData
);
166 myDataLen
= CFDataGetLength(xmlData
);
168 /* send the key & data to the server, get new instance id */
169 status
= configset(storePrivate
->server
,
182 if (status
!= KERN_SUCCESS
) {
183 if (status
!= MACH_SEND_INVALID_DEST
)
184 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configset(): %s"), mach_error_string(status
));
185 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
186 storePrivate
->server
= MACH_PORT_NULL
;
191 if (sc_status
!= kSCStatusOK
) {
192 _SCErrorSet(sc_status
);