2 * Copyright (c) 2000, 2001, 2003, 2004, 2006 Apple Computer, 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>
39 __SCDynamicStoreAddValue(SCDynamicStoreRef store
, CFStringRef key
, CFDataRef value
, Boolean internal
)
41 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
42 int sc_status
= kSCStatusOK
;
45 if ((store
== NULL
) || (storePrivate
->server
== MACH_PORT_NULL
)) {
46 return kSCStatusNoStoreSession
; /* you must have an open session to play */
50 SCTrace(TRUE
, _configd_trace
,
51 CFSTR("%s%s : %5d : %@\n"),
52 internal
? "*add " : "add ",
53 storePrivate
->useSessionKeys
? "t " : " ",
59 * 1. Ensure that we hold the lock.
61 sc_status
= __SCDynamicStoreLock(store
, TRUE
);
62 if (sc_status
!= kSCStatusOK
) {
67 * 2. Ensure that this is a new key.
69 sc_status
= __SCDynamicStoreCopyValue(store
, key
, &tempValue
, TRUE
);
72 /* store key does not exist, proceed */
76 /* store key exists, sorry */
78 sc_status
= kSCStatusKeyExists
;
83 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreAddValue __SCDynamicStoreCopyValue(): %s"), SCErrorString(sc_status
));
89 * 3. Save the new key.
91 sc_status
= __SCDynamicStoreSetValue(store
, key
, value
, TRUE
);
94 * 4. Release our lock.
99 __SCDynamicStoreUnlock(store
, TRUE
);
107 _configadd(mach_port_t server
,
108 xmlData_t keyRef
, /* raw XML bytes */
109 mach_msg_type_number_t keyLen
,
110 xmlData_t dataRef
, /* raw XML bytes */
111 mach_msg_type_number_t dataLen
,
116 CFStringRef key
= NULL
; /* key (un-serialized) */
117 CFDataRef data
= NULL
; /* data (un-serialized) */
118 serverSessionRef mySession
= getSession(server
);
120 *sc_status
= kSCStatusOK
;
122 /* un-serialize the key */
123 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
124 *sc_status
= kSCStatusFailed
;
128 /* un-serialize the data */
129 if (!_SCUnserializeData(&data
, (void *)dataRef
, dataLen
)) {
130 *sc_status
= kSCStatusFailed
;
133 if (*sc_status
!= kSCStatusOK
) {
137 if (!isA_CFString(key
)) {
138 *sc_status
= kSCStatusInvalidArgument
;
142 if (mySession
== NULL
) {
143 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
147 *sc_status
= __SCDynamicStoreAddValue(mySession
->store
, key
, data
, FALSE
);
148 if (*sc_status
== kSCStatusOK
) {
154 if (key
!= NULL
) CFRelease(key
);
155 if (data
!= NULL
) CFRelease(data
);
163 _configadd_s(mach_port_t server
,
164 xmlData_t keyRef
, /* raw XML bytes */
165 mach_msg_type_number_t keyLen
,
166 xmlData_t dataRef
, /* raw XML bytes */
167 mach_msg_type_number_t dataLen
,
172 CFDataRef data
= NULL
; /* data (un-serialized) */
173 CFStringRef key
= NULL
; /* key (un-serialized) */
174 serverSessionRef mySession
= getSession(server
);
175 SCDynamicStorePrivateRef storePrivate
;
176 Boolean useSessionKeys
;
178 *sc_status
= kSCStatusOK
;
180 /* un-serialize the key */
181 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
182 *sc_status
= kSCStatusFailed
;
185 /* un-serialize the data */
186 if (!_SCUnserializeData(&data
, (void *)dataRef
, dataLen
)) {
187 *sc_status
= kSCStatusFailed
;
190 if (*sc_status
!= kSCStatusOK
) {
194 if (!isA_CFString(key
)) {
195 *sc_status
= kSCStatusInvalidArgument
;
199 if (mySession
== NULL
) {
200 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
204 // force "useSessionKeys"
205 storePrivate
= (SCDynamicStorePrivateRef
)mySession
->store
;
206 useSessionKeys
= storePrivate
->useSessionKeys
;
207 storePrivate
->useSessionKeys
= TRUE
;
209 *sc_status
= __SCDynamicStoreAddValue(mySession
->store
, key
, data
, FALSE
);
210 if (*sc_status
== kSCStatusOK
) {
214 // restore "useSessionKeys"
215 storePrivate
->useSessionKeys
= useSessionKeys
;
219 if (key
!= NULL
) CFRelease(key
);
220 if (data
!= NULL
) CFRelease(data
);