2 * Copyright (c) 2000-2002 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 if (!_SCSerialize(keysToSet
, &xmlSet
, (void **)&mySetRef
, &mySetLen
)) {
79 _SCErrorSet(kSCStatusFailed
);
84 /* serialize the keys to remove */
86 if (!_SCSerialize(keysToRemove
, &xmlRemove
, (void **)&myRemoveRef
, &myRemoveLen
)) {
87 if (xmlSet
) CFRelease(xmlSet
);
88 _SCErrorSet(kSCStatusFailed
);
93 /* serialize the keys to notify */
95 if (!_SCSerialize(keysToNotify
, &xmlNotify
, (void **)&myNotifyRef
, &myNotifyLen
)) {
96 if (xmlSet
) CFRelease(xmlSet
);
97 if (xmlRemove
) CFRelease(xmlRemove
);
98 _SCErrorSet(kSCStatusFailed
);
103 /* send the keys and patterns, fetch the associated result from the server */
104 status
= configset_m(storePrivate
->server
,
114 if (xmlSet
) CFRelease(xmlSet
);
115 if (xmlRemove
) CFRelease(xmlRemove
);
116 if (xmlNotify
) CFRelease(xmlNotify
);
118 if (status
!= KERN_SUCCESS
) {
119 if (status
!= MACH_SEND_INVALID_DEST
)
120 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configset_m(): %s"), mach_error_string(status
));
121 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
122 storePrivate
->server
= MACH_PORT_NULL
;
127 if (sc_status
!= kSCStatusOK
) {
128 _SCErrorSet(sc_status
);
136 SCDynamicStoreSetValue(SCDynamicStoreRef store
, CFStringRef key
, CFPropertyListRef value
)
138 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
139 kern_return_t status
;
140 CFDataRef xmlKey
; /* serialized key */
143 CFDataRef xmlData
; /* serialized data */
149 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("SCDynamicStoreSetValue:"));
150 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
151 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" value = %@"), value
);
154 /* sorry, you must provide a session */
155 _SCErrorSet(kSCStatusNoStoreSession
);
159 if (storePrivate
->server
== MACH_PORT_NULL
) {
160 /* sorry, you must have an open session to play */
161 _SCErrorSet(kSCStatusNoStoreServer
);
165 /* serialize the key */
166 if (!_SCSerialize(key
, &xmlKey
, (void **)&myKeyRef
, &myKeyLen
)) {
167 _SCErrorSet(kSCStatusFailed
);
171 /* serialize the data */
172 if (!_SCSerialize(value
, &xmlData
, (void **)&myDataRef
, &myDataLen
)) {
174 _SCErrorSet(kSCStatusFailed
);
178 /* send the key & data to the server, get new instance id */
179 status
= configset(storePrivate
->server
,
192 if (status
!= KERN_SUCCESS
) {
193 if (status
!= MACH_SEND_INVALID_DEST
)
194 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configset(): %s"), mach_error_string(status
));
195 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
196 storePrivate
->server
= MACH_PORT_NULL
;
201 if (sc_status
!= kSCStatusOK
) {
202 _SCErrorSet(sc_status
);