2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Modification History
29 * June 1, 2001 Allan Nathanson <ajn@apple.com>
30 * - public API conversion
32 * March 24, 2000 Allan Nathanson <ajn@apple.com>
36 #include <mach/mach.h>
37 #include <mach/mach_error.h>
39 #include <SystemConfiguration/SystemConfiguration.h>
40 #include <SystemConfiguration/SCPrivate.h>
41 #include "SCDynamicStoreInternal.h"
42 #include "config.h" /* MiG generated file */
46 SCDynamicStoreSetMultiple(SCDynamicStoreRef store
,
47 CFDictionaryRef keysToSet
,
48 CFArrayRef keysToRemove
,
49 CFArrayRef keysToNotify
)
51 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
53 CFDataRef xmlSet
= NULL
; /* key/value pairs to set (XML serialized) */
54 xmlData_t mySetRef
= NULL
; /* key/value pairs to set (serialized) */
56 CFDataRef xmlRemove
= NULL
; /* keys to remove (XML serialized) */
57 xmlData_t myRemoveRef
= NULL
; /* keys to remove (serialized) */
58 CFIndex myRemoveLen
= 0;
59 CFDataRef xmlNotify
= NULL
; /* keys to notify (XML serialized) */
60 xmlData_t myNotifyRef
= NULL
; /* keys to notify (serialized) */
61 CFIndex myNotifyLen
= 0;
65 SCLog(TRUE
, LOG_DEBUG
, CFSTR("SCDynamicStoreSetMultiple:"));
66 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" keysToSet = %@"), keysToSet
);
67 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" keysToRemove = %@"), keysToRemove
);
68 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" keysToNotify = %@"), keysToNotify
);
72 /* sorry, you must provide a session */
73 _SCErrorSet(kSCStatusNoStoreSession
);
77 if (storePrivate
->server
== MACH_PORT_NULL
) {
78 _SCErrorSet(kSCStatusNoStoreServer
);
79 return NULL
; /* you must have an open session to play */
82 /* serialize the key/value pairs to set*/
84 CFDictionaryRef newInfo
;
87 newInfo
= _SCSerializeMultiple(keysToSet
);
89 _SCErrorSet(kSCStatusFailed
);
93 ok
= _SCSerialize(newInfo
, &xmlSet
, (void **)&mySetRef
, &mySetLen
);
97 _SCErrorSet(kSCStatusFailed
);
102 /* serialize the keys to remove */
104 if (!_SCSerialize(keysToRemove
, &xmlRemove
, (void **)&myRemoveRef
, &myRemoveLen
)) {
105 if (xmlSet
) CFRelease(xmlSet
);
106 _SCErrorSet(kSCStatusFailed
);
111 /* serialize the keys to notify */
113 if (!_SCSerialize(keysToNotify
, &xmlNotify
, (void **)&myNotifyRef
, &myNotifyLen
)) {
114 if (xmlSet
) CFRelease(xmlSet
);
115 if (xmlRemove
) CFRelease(xmlRemove
);
116 _SCErrorSet(kSCStatusFailed
);
121 /* send the keys and patterns, fetch the associated result from the server */
122 status
= configset_m(storePrivate
->server
,
132 if (xmlSet
) CFRelease(xmlSet
);
133 if (xmlRemove
) CFRelease(xmlRemove
);
134 if (xmlNotify
) CFRelease(xmlNotify
);
136 if (status
!= KERN_SUCCESS
) {
137 if (status
!= MACH_SEND_INVALID_DEST
)
138 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configset_m(): %s"), mach_error_string(status
));
139 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
140 storePrivate
->server
= MACH_PORT_NULL
;
145 if (sc_status
!= kSCStatusOK
) {
146 _SCErrorSet(sc_status
);
154 SCDynamicStoreSetValue(SCDynamicStoreRef store
, CFStringRef key
, CFPropertyListRef value
)
156 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
157 kern_return_t status
;
158 CFDataRef utfKey
; /* serialized key */
161 CFDataRef xmlData
; /* serialized data */
168 SCLog(TRUE
, LOG_DEBUG
, CFSTR("SCDynamicStoreSetValue:"));
169 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
170 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" value = %@"), value
);
174 /* sorry, you must provide a session */
175 _SCErrorSet(kSCStatusNoStoreSession
);
179 if (storePrivate
->server
== MACH_PORT_NULL
) {
180 /* sorry, you must have an open session to play */
181 _SCErrorSet(kSCStatusNoStoreServer
);
185 /* serialize the key */
186 if (!_SCSerializeString(key
, &utfKey
, (void **)&myKeyRef
, &myKeyLen
)) {
187 _SCErrorSet(kSCStatusFailed
);
191 /* serialize the data */
192 if (!_SCSerialize(value
, &xmlData
, (void **)&myDataRef
, &myDataLen
)) {
194 _SCErrorSet(kSCStatusFailed
);
198 /* send the key & data to the server, get new instance id */
199 status
= configset(storePrivate
->server
,
212 if (status
!= KERN_SUCCESS
) {
213 if (status
!= MACH_SEND_INVALID_DEST
)
214 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configset(): %s"), mach_error_string(status
));
215 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
216 storePrivate
->server
= MACH_PORT_NULL
;
221 if (sc_status
!= kSCStatusOK
) {
222 _SCErrorSet(sc_status
);