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 __SCDynamicStoreRemoveValue(SCDynamicStoreRef store
, CFStringRef key
, Boolean internal
)
43 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
44 int sc_status
= kSCStatusOK
;
46 CFMutableDictionaryRef newDict
;
47 CFStringRef sessionKey
;
49 if (_configd_verbose
) {
50 SCLog(TRUE
, LOG_DEBUG
, CFSTR("__SCDynamicStoreRemoveValue:"));
51 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
54 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
55 return kSCStatusNoStoreSession
; /* you must have an open session to play */
59 SCTrace(TRUE
, _configd_trace
,
60 CFSTR("%s : %5d : %@\n"),
61 internal
? "*remove" : "remove ",
67 * 1. Ensure that we hold the lock.
69 sc_status
= __SCDynamicStoreLock(store
, TRUE
);
70 if (sc_status
!= kSCStatusOK
) {
75 * 2. Ensure that this key exists.
77 dict
= CFDictionaryGetValue(storeData
, key
);
78 if ((dict
== NULL
) || (CFDictionaryContainsKey(dict
, kSCDData
) == FALSE
)) {
79 /* key doesn't exist (or data never defined) */
80 sc_status
= kSCStatusNoKey
;
83 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
86 * 3. Mark this key as "changed". Any "watchers" will be
87 * notified as soon as the lock is released.
89 CFSetAddValue(changedKeys
, key
);
92 * 4. Add this key to a deferred cleanup list so that, after
93 * the change notifications are posted, any associated
94 * regex keys can be removed.
96 CFSetAddValue(deferredRemovals
, key
);
99 * 5. Check if this is a session key and, if so, add it
100 * to the (session) removal list
102 sessionKey
= CFDictionaryGetValue(newDict
, kSCDSession
);
104 CFStringRef removedKey
;
106 /* We are no longer a session key! */
107 CFDictionaryRemoveValue(newDict
, kSCDSession
);
109 /* add this session key to the (session) removal list */
110 removedKey
= CFStringCreateWithFormat(NULL
, 0, CFSTR("%@:%@"), sessionKey
, key
);
111 CFSetAddValue(removedSessionKeys
, removedKey
);
112 CFRelease(removedKey
);
116 * 6. Remove data and update/remove the dictionary store entry.
118 CFDictionaryRemoveValue(newDict
, kSCDData
);
119 if (CFDictionaryGetCount(newDict
) > 0) {
120 /* this key is still being "watched" */
121 CFDictionarySetValue(storeData
, key
, newDict
);
123 /* no information left, remove the empty dictionary */
124 CFDictionaryRemoveValue(storeData
, key
);
129 * 7. Release our lock.
132 __SCDynamicStoreUnlock(store
, TRUE
);
140 _configremove(mach_port_t server
,
141 xmlData_t keyRef
, /* raw XML bytes */
142 mach_msg_type_number_t keyLen
,
146 serverSessionRef mySession
= getSession(server
);
147 CFStringRef key
; /* key (un-serialized) */
149 if (_configd_verbose
) {
150 SCLog(TRUE
, LOG_DEBUG
, CFSTR("Remove key from configuration database."));
151 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
154 /* un-serialize the key */
155 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
156 *sc_status
= kSCStatusFailed
;
160 if (!isA_CFString(key
)) {
161 *sc_status
= kSCStatusInvalidArgument
;
167 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
172 *sc_status
= __SCDynamicStoreRemoveValue(mySession
->store
, key
, FALSE
);