2 * Copyright (c) 2000-2006, 2009-2011, 2013, 2016 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
30 * March 24, 2000 Allan Nathanson <ajn@apple.com>
34 #include "SCDynamicStoreInternal.h"
35 #include "config.h" /* MiG generated file */
39 SCDynamicStoreSetMultiple(SCDynamicStoreRef store
,
40 CFDictionaryRef keysToSet
,
41 CFArrayRef keysToRemove
,
42 CFArrayRef keysToNotify
)
44 SCDynamicStorePrivateRef storePrivate
;
46 CFDataRef xmlSet
= NULL
; /* key/value pairs to set (XML serialized) */
47 xmlData_t mySetRef
= NULL
; /* key/value pairs to set (serialized) */
49 CFDataRef xmlRemove
= NULL
; /* keys to remove (XML serialized) */
50 xmlData_t myRemoveRef
= NULL
; /* keys to remove (serialized) */
51 CFIndex myRemoveLen
= 0;
52 CFDataRef xmlNotify
= NULL
; /* keys to notify (XML serialized) */
53 xmlData_t myNotifyRef
= NULL
; /* keys to notify (serialized) */
54 CFIndex myNotifyLen
= 0;
58 store
= __SCDynamicStoreNullSession();
60 /* sorry, you must provide a session */
61 _SCErrorSet(kSCStatusNoStoreSession
);
66 storePrivate
= (SCDynamicStorePrivateRef
)store
;
67 if (storePrivate
->server
== MACH_PORT_NULL
) {
68 _SCErrorSet(kSCStatusNoStoreServer
);
69 return FALSE
; /* you must have an open session to play */
72 /* serialize the key/value pairs to set*/
73 if (keysToSet
!= NULL
) {
74 CFDictionaryRef newInfo
;
77 newInfo
= _SCSerializeMultiple(keysToSet
);
78 if (newInfo
== NULL
) {
79 _SCErrorSet(kSCStatusInvalidArgument
);
83 ok
= _SCSerialize(newInfo
, &xmlSet
, (void **)&mySetRef
, &mySetLen
);
86 _SCErrorSet(kSCStatusInvalidArgument
);
91 /* serialize the keys to remove */
92 if (keysToRemove
!= NULL
) {
93 if (!_SCSerialize(keysToRemove
, &xmlRemove
, (void **)&myRemoveRef
, &myRemoveLen
)) {
94 if (xmlSet
!= NULL
) CFRelease(xmlSet
);
95 _SCErrorSet(kSCStatusInvalidArgument
);
100 /* serialize the keys to notify */
101 if (keysToNotify
!= NULL
) {
102 if (!_SCSerialize(keysToNotify
, &xmlNotify
, (void **)&myNotifyRef
, &myNotifyLen
)) {
103 if (xmlSet
!= NULL
) CFRelease(xmlSet
);
104 if (xmlRemove
!= NULL
) CFRelease(xmlRemove
);
105 _SCErrorSet(kSCStatusInvalidArgument
);
110 os_activity_scope(storePrivate
->activity
);
114 /* send the keys and patterns, fetch the associated result from the server */
115 status
= configset_m(storePrivate
->server
,
117 (mach_msg_type_number_t
)mySetLen
,
119 (mach_msg_type_number_t
)myRemoveLen
,
121 (mach_msg_type_number_t
)myNotifyLen
,
124 if (__SCDynamicStoreCheckRetryAndHandleError(store
,
127 "SCDynamicStoreSetMultiple configset_m()")) {
132 if (xmlSet
!= NULL
) CFRelease(xmlSet
);
133 if (xmlRemove
!= NULL
) CFRelease(xmlRemove
);
134 if (xmlNotify
!= NULL
) CFRelease(xmlNotify
);
136 if (sc_status
!= kSCStatusOK
) {
137 _SCErrorSet(sc_status
);
145 SCDynamicStoreSetValue(SCDynamicStoreRef store
, CFStringRef key
, CFPropertyListRef value
)
147 SCDynamicStorePrivateRef storePrivate
;
148 kern_return_t status
;
149 CFDataRef utfKey
; /* serialized key */
152 CFDataRef xmlData
; /* serialized data */
159 store
= __SCDynamicStoreNullSession();
161 /* sorry, you must provide a session */
162 _SCErrorSet(kSCStatusNoStoreSession
);
167 storePrivate
= (SCDynamicStorePrivateRef
)store
;
168 if (storePrivate
->server
== MACH_PORT_NULL
) {
169 /* sorry, you must have an open session to play */
170 _SCErrorSet(kSCStatusNoStoreServer
);
174 /* serialize the key */
175 if (!_SCSerializeString(key
, &utfKey
, (void **)&myKeyRef
, &myKeyLen
)) {
176 _SCErrorSet(kSCStatusInvalidArgument
);
180 /* serialize the data */
181 if (!_SCSerialize(value
, &xmlData
, (void **)&myDataRef
, &myDataLen
)) {
183 _SCErrorSet(kSCStatusInvalidArgument
);
187 os_activity_scope(storePrivate
->activity
);
191 /* send the key & data to the server, get new instance id */
192 status
= configset(storePrivate
->server
,
194 (mach_msg_type_number_t
)myKeyLen
,
196 (mach_msg_type_number_t
)myDataLen
,
201 if (__SCDynamicStoreCheckRetryAndHandleError(store
,
204 "SCDynamicStoreSetValue configset()")) {
212 if (sc_status
!= kSCStatusOK
) {
213 _SCErrorSet(sc_status
);