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>
41 __SCDynamicStoreAddValue(SCDynamicStoreRef store
, CFStringRef key
, CFDataRef value
)
43 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
44 int sc_status
= kSCStatusOK
;
47 if (_configd_verbose
) {
48 CFPropertyListRef val
;
50 (void) _SCUnserialize(&val
, value
, NULL
, NULL
);
51 SCLog(TRUE
, LOG_DEBUG
, CFSTR("__SCDynamicStoreAddValue:"));
52 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
53 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" value = %@"), val
);
57 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
58 return kSCStatusNoStoreSession
; /* you must have an open session to play */
62 SCTrace(TRUE
, _configd_trace
, CFSTR("add : %5d : %@\n"), storePrivate
->server
, key
);
66 * 1. Ensure that we hold the lock.
68 sc_status
= __SCDynamicStoreLock(store
, TRUE
);
69 if (sc_status
!= kSCStatusOK
) {
74 * 2. Ensure that this is a new key.
76 sc_status
= __SCDynamicStoreCopyValue(store
, key
, &tempValue
, TRUE
);
79 /* store key does not exist, proceed */
83 /* store key exists, sorry */
85 sc_status
= kSCStatusKeyExists
;
89 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" __SCDynamicStoreCopyValue(): %s"), SCErrorString(sc_status
));
94 * 3. Save the new key.
96 sc_status
= __SCDynamicStoreSetValue(store
, key
, value
, TRUE
);
99 * 4. Release our lock.
102 __SCDynamicStoreUnlock(store
, TRUE
);
110 _configadd(mach_port_t server
,
111 xmlData_t keyRef
, /* raw XML bytes */
112 mach_msg_type_number_t keyLen
,
113 xmlData_t dataRef
, /* raw XML bytes */
114 mach_msg_type_number_t dataLen
,
119 serverSessionRef mySession
= getSession(server
);
120 CFStringRef key
; /* key (un-serialized) */
121 CFDataRef data
; /* data (un-serialized) */
123 if (_configd_verbose
) {
124 SCLog(TRUE
, LOG_DEBUG
, CFSTR("Add key to configuration database."));
125 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
128 *sc_status
= kSCStatusOK
;
130 /* un-serialize the key */
131 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
132 *sc_status
= kSCStatusFailed
;
133 } else if (!isA_CFString(key
)) {
134 *sc_status
= kSCStatusInvalidArgument
;
137 /* un-serialize the data */
138 if (!_SCUnserializeData(&data
, (void *)dataRef
, dataLen
)) {
139 *sc_status
= kSCStatusFailed
;
143 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
146 if (*sc_status
!= kSCStatusOK
) {
147 if (key
) CFRelease(key
);
148 if (data
) CFRelease(data
);
152 *sc_status
= __SCDynamicStoreAddValue(mySession
->store
, key
, data
);