2 * Copyright (c) 2000 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>
37 __SCDynamicStoreAddValue(SCDynamicStoreRef store
, CFStringRef key
, CFPropertyListRef value
)
39 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
40 int sc_status
= kSCStatusOK
;
41 CFPropertyListRef tempValue
;
43 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreAddValue:"));
44 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
45 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" value = %@"), value
);
47 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
48 return kSCStatusNoStoreSession
; /* you must have an open session to play */
52 * 1. Ensure that we hold the lock.
54 sc_status
= __SCDynamicStoreLock(store
, TRUE
);
55 if (sc_status
!= kSCStatusOK
) {
60 * 2. Ensure that this is a new key.
62 sc_status
= __SCDynamicStoreCopyValue(store
, key
, &tempValue
);
65 /* store key does not exist, proceed */
69 /* store key exists, sorry */
71 sc_status
= kSCStatusKeyExists
;
75 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" _SCDGet(): %s"), SCErrorString(sc_status
));
80 * 3. Save the new key.
82 sc_status
= __SCDynamicStoreSetValue(store
, key
, value
);
85 * 4. Release our lock.
88 __SCDynamicStoreUnlock(store
, TRUE
);
95 _configadd(mach_port_t server
,
96 xmlData_t keyRef
, /* raw XML bytes */
97 mach_msg_type_number_t keyLen
,
98 xmlData_t dataRef
, /* raw XML bytes */
99 mach_msg_type_number_t dataLen
,
104 kern_return_t status
;
105 serverSessionRef mySession
= getSession(server
);
106 CFDataRef xmlKey
; /* key (XML serialized) */
107 CFStringRef key
; /* key (un-serialized) */
108 CFDataRef xmlData
; /* data (XML serialized) */
109 CFPropertyListRef data
; /* data (un-serialized) */
110 CFStringRef xmlError
;
112 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("Add key to configuration database."));
113 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
115 *sc_status
= kSCStatusOK
;
117 /* un-serialize the key */
118 xmlKey
= CFDataCreate(NULL
, keyRef
, keyLen
);
119 status
= vm_deallocate(mach_task_self(), (vm_address_t
)keyRef
, keyLen
);
120 if (status
!= KERN_SUCCESS
) {
121 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
122 /* non-fatal???, proceed */
124 key
= CFPropertyListCreateFromXMLData(NULL
,
126 kCFPropertyListImmutable
,
131 SCLog(_configd_verbose
, LOG_DEBUG
,
132 CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
136 *sc_status
= kSCStatusFailed
;
137 } else if (!isA_CFString(key
)) {
138 *sc_status
= kSCStatusInvalidArgument
;
141 /* un-serialize the data */
142 xmlData
= CFDataCreate(NULL
, dataRef
, dataLen
);
143 status
= vm_deallocate(mach_task_self(), (vm_address_t
)dataRef
, dataLen
);
144 if (status
!= KERN_SUCCESS
) {
145 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
146 /* non-fatal???, proceed */
148 data
= CFPropertyListCreateFromXMLData(NULL
,
150 kCFPropertyListImmutable
,
155 SCLog(_configd_verbose
, LOG_DEBUG
,
156 CFSTR("CFPropertyListCreateFromXMLData() data: %@"),
160 *sc_status
= kSCStatusFailed
;
161 } else if (!isA_CFPropertyList(data
)) {
162 *sc_status
= kSCStatusInvalidArgument
;
165 if (*sc_status
!= kSCStatusOK
) {
166 if (key
) CFRelease(key
);
167 if (data
) CFRelease(data
);
171 *sc_status
= __SCDynamicStoreAddValue(mySession
->store
, key
, data
);