2 * Copyright (c) 2000-2002 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 __SCDynamicStoreRemoveValue(SCDynamicStoreRef store
, CFStringRef key
)
39 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
40 int sc_status
= kSCStatusOK
;
42 CFMutableDictionaryRef newDict
;
43 CFStringRef sessionKey
;
45 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreRemoveValue:"));
46 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
48 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
49 return kSCStatusNoStoreSession
; /* you must have an open session to play */
53 * 1. Ensure that we hold the lock.
55 sc_status
= __SCDynamicStoreLock(store
, TRUE
);
56 if (sc_status
!= kSCStatusOK
) {
61 * 2. Ensure that this key exists.
63 dict
= CFDictionaryGetValue(storeData
, key
);
64 if ((dict
== NULL
) || (CFDictionaryContainsKey(dict
, kSCDData
) == FALSE
)) {
65 /* key doesn't exist (or data never defined) */
66 sc_status
= kSCStatusNoKey
;
69 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
72 * 3. Mark this key as "changed". Any "watchers" will be
73 * notified as soon as the lock is released.
75 CFSetAddValue(changedKeys
, key
);
78 * 4. Add this key to a deferred cleanup list so that, after
79 * the change notifications are posted, any associated
80 * regex keys can be removed.
82 CFSetAddValue(deferredRemovals
, key
);
85 * 5. Check if this is a session key and, if so, add it
86 * to the (session) removal list
88 sessionKey
= CFDictionaryGetValue(newDict
, kSCDSession
);
90 CFStringRef removedKey
;
92 /* We are no longer a session key! */
93 CFDictionaryRemoveValue(newDict
, kSCDSession
);
95 /* add this session key to the (session) removal list */
96 removedKey
= CFStringCreateWithFormat(NULL
, 0, CFSTR("%@:%@"), sessionKey
, key
);
97 CFSetAddValue(removedSessionKeys
, removedKey
);
98 CFRelease(removedKey
);
102 * 6. Remove data, remove instance, and update/remove
103 * the dictionary store entry.
105 CFDictionaryRemoveValue(newDict
, kSCDData
);
106 CFDictionaryRemoveValue(newDict
, kSCDInstance
);
107 if (CFDictionaryGetCount(newDict
) > 0) {
108 /* this key is still being "watched" */
109 CFDictionarySetValue(storeData
, key
, newDict
);
111 /* no information left, remove the empty dictionary */
112 CFDictionaryRemoveValue(storeData
, key
);
117 * 7. Release our lock.
120 __SCDynamicStoreUnlock(store
, TRUE
);
127 _configremove(mach_port_t server
,
128 xmlData_t keyRef
, /* raw XML bytes */
129 mach_msg_type_number_t keyLen
,
133 serverSessionRef mySession
= getSession(server
);
134 CFStringRef key
; /* key (un-serialized) */
136 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("Remove key from configuration database."));
137 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
139 /* un-serialize the key */
140 if (!_SCUnserialize((CFPropertyListRef
*)&key
, (void *)keyRef
, keyLen
)) {
141 *sc_status
= kSCStatusFailed
;
145 if (!isA_CFString(key
)) {
147 *sc_status
= kSCStatusInvalidArgument
;
151 *sc_status
= __SCDynamicStoreRemoveValue(mySession
->store
, key
);