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@
27 _SCDRemove(SCDSessionRef session
, CFStringRef key
)
29 SCDSessionPrivateRef sessionPrivate
= (SCDSessionPrivateRef
)session
;
30 SCDStatus scd_status
= SCD_OK
;
33 CFMutableDictionaryRef newDict
;
34 CFStringRef sessionKey
;
36 SCDLog(LOG_DEBUG
, CFSTR("_SCDRemove:"));
37 SCDLog(LOG_DEBUG
, CFSTR(" key = %@"), key
);
39 if ((session
== NULL
) || (sessionPrivate
->server
== MACH_PORT_NULL
)) {
40 return SCD_NOSESSION
; /* you can't do anything with a closed session */
44 * 1. Determine if the cache lock is currently held and acquire
45 * the lock if necessary.
47 wasLocked
= SCDOptionGet(NULL
, kSCDOptionIsLocked
);
49 scd_status
= _SCDLock(session
);
50 if (scd_status
!= SCD_OK
) {
51 SCDLog(LOG_DEBUG
, CFSTR(" _SCDLock(): %s"), SCDError(scd_status
));
57 * 2. Ensure that this key exists.
59 dict
= CFDictionaryGetValue(cacheData
, key
);
60 if ((dict
== NULL
) || (CFDictionaryContainsKey(dict
, kSCDData
) == FALSE
)) {
61 /* key doesn't exist (or data never defined) */
62 scd_status
= SCD_NOKEY
;
65 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
68 * 3. Mark this key as "changed". Any "watchers" will be
69 * notified as soon as the lock is released.
71 CFSetAddValue(changedKeys
, key
);
74 * 4. Add this key to a deferred cleanup list so that, after
75 * the change notifications are posted, any associated
76 * regex keys can be removed.
78 CFSetAddValue(deferredRemovals
, key
);
81 * 5. Check if this is a session key and, if so, add it
82 * to the (session) removal list
84 sessionKey
= CFDictionaryGetValue(newDict
, kSCDSession
);
86 CFStringRef removedKey
;
88 /* We are no longer a session key! */
89 CFDictionaryRemoveValue(newDict
, kSCDSession
);
91 /* add this session key to the (session) removal list */
92 removedKey
= CFStringCreateWithFormat(NULL
, 0, CFSTR("%@:%@"), sessionKey
, key
);
93 CFSetAddValue(removedSessionKeys
, removedKey
);
94 CFRelease(removedKey
);
98 * 6. Remove data, remove instance, and update/remove
99 * the dictionary cache entry.
101 CFDictionaryRemoveValue(newDict
, kSCDData
);
102 CFDictionaryRemoveValue(newDict
, kSCDInstance
);
103 if (CFDictionaryGetCount(newDict
) > 0) {
104 /* this key is still being "watched" */
105 CFDictionarySetValue(cacheData
, key
, newDict
);
107 /* no information left, remove the empty dictionary */
108 CFDictionaryRemoveValue(cacheData
, key
);
113 * 7. Release the lock if we acquired it as part of this request.
124 _configremove(mach_port_t server
,
125 xmlData_t keyRef
, /* raw XML bytes */
126 mach_msg_type_number_t keyLen
,
130 kern_return_t status
;
131 serverSessionRef mySession
= getSession(server
);
132 CFDataRef xmlKey
; /* key (XML serialized) */
133 CFStringRef key
; /* key (un-serialized) */
134 CFStringRef xmlError
;
136 SCDLog(LOG_DEBUG
, CFSTR("Remove key from configuration database."));
137 SCDLog(LOG_DEBUG
, CFSTR(" server = %d"), server
);
139 /* un-serialize the key */
140 xmlKey
= CFDataCreate(NULL
, keyRef
, keyLen
);
141 status
= vm_deallocate(mach_task_self(), (vm_address_t
)keyRef
, keyLen
);
142 if (status
!= KERN_SUCCESS
) {
143 SCDLog(LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
144 /* non-fatal???, proceed */
146 key
= CFPropertyListCreateFromXMLData(NULL
,
148 kCFPropertyListImmutable
,
152 SCDLog(LOG_DEBUG
, CFSTR("CFPropertyListCreateFromXMLData() key: %s"), xmlError
);
153 *scd_status
= SCD_FAILED
;
157 *scd_status
= _SCDRemove(mySession
->session
, key
);