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>
39 isMySessionKey(CFStringRef sessionKey
, CFStringRef key
)
42 CFStringRef storeSessionKey
;
44 dict
= CFDictionaryGetValue(storeData
, key
);
46 /* if key no longer exists */
50 storeSessionKey
= CFDictionaryGetValue(dict
, kSCDSession
);
51 if (!storeSessionKey
) {
52 /* if this is not a session key */
56 if (!CFEqual(sessionKey
, storeSessionKey
)) {
57 /* if this is not "my" session key */
66 __SCDynamicStoreClose(SCDynamicStoreRef
*store
)
68 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)*store
;
70 CFStringRef sessionKey
;
73 serverSessionRef mySession
;
75 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreClose:"));
77 if ((*store
== NULL
) || (storePrivate
->server
== MACH_PORT_NULL
)) {
78 return kSCStatusNoStoreSession
; /* you must have an open session to play */
81 /* Remove notification keys */
82 if ((keyCnt
= CFSetGetCount(storePrivate
->keys
)) > 0) {
84 CFArrayRef keysToRemove
;
87 watchedKeys
= CFAllocatorAllocate(NULL
, keyCnt
* sizeof(CFStringRef
), 0);
88 CFSetGetValues(storePrivate
->keys
, watchedKeys
);
89 keysToRemove
= CFArrayCreate(NULL
, watchedKeys
, keyCnt
, &kCFTypeArrayCallBacks
);
90 CFAllocatorDeallocate(NULL
, watchedKeys
);
91 for (i
=0; i
<keyCnt
; i
++) {
92 (void) __SCDynamicStoreRemoveWatchedKey(*store
,
93 CFArrayGetValueAtIndex(keysToRemove
, i
),
96 CFRelease(keysToRemove
);
99 /* Remove regex notification keys */
100 if ((keyCnt
= CFSetGetCount(storePrivate
->reKeys
)) > 0) {
102 CFArrayRef keysToRemove
;
105 watchedKeys
= CFAllocatorAllocate(NULL
, keyCnt
* sizeof(CFStringRef
), 0);
106 CFSetGetValues(storePrivate
->reKeys
, watchedKeys
);
107 keysToRemove
= CFArrayCreate(NULL
, watchedKeys
, keyCnt
, &kCFTypeArrayCallBacks
);
108 CFAllocatorDeallocate(NULL
, watchedKeys
);
109 for (i
=0; i
<keyCnt
; i
++) {
110 (void) __SCDynamicStoreRemoveWatchedKey(*store
,
111 CFArrayGetValueAtIndex(keysToRemove
, i
),
114 CFRelease(keysToRemove
);
117 /* Remove/cancel any outstanding notification requests. */
118 (void) __SCDynamicStoreNotifyCancel(*store
);
120 /* Remove any session keys */
121 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), storePrivate
->server
);
122 dict
= CFDictionaryGetValue(sessionData
, sessionKey
);
123 keys
= CFDictionaryGetValue(dict
, kSCDSessionKeys
);
124 if (keys
&& ((keyCnt
= CFArrayGetCount(keys
)) > 0)) {
129 * if necessary, claim a lock to ensure that we inform
130 * any processes that a session key was removed.
132 wasLocked
= (storeLocked
> 0);
134 (void) __SCDynamicStoreLock(*store
, FALSE
);
137 /* remove keys from "locked" store" */
138 for (i
=0; i
<keyCnt
; i
++) {
139 if (isMySessionKey(sessionKey
, CFArrayGetValueAtIndex(keys
, i
))) {
140 (void) __SCDynamicStoreRemoveValue(*store
, CFArrayGetValueAtIndex(keys
, i
));
145 /* remove keys from "unlocked" store" */
146 _swapLockedStoreData();
147 for (i
=0; i
<keyCnt
; i
++) {
148 if (isMySessionKey(sessionKey
, CFArrayGetValueAtIndex(keys
, i
)))
149 (void) __SCDynamicStoreRemoveValue(*store
, CFArrayGetValueAtIndex(keys
, i
));
151 _swapLockedStoreData();
155 * Note: everyone who calls __SCDynamicStoreClose() ends
156 * up removing this sessions dictionary. As such,
157 * we don't need to worry about the session keys.
160 CFRelease(sessionKey
);
162 /* release the lock */
163 if (storePrivate
->locked
) {
164 (void) __SCDynamicStoreUnlock(*store
, FALSE
);
168 * Remove the run loop source on the server port (for this
169 * client). Then, invalidate and release the port.
171 mySession
= getSession(storePrivate
->server
);
172 if (mySession
->serverRunLoopSource
) {
173 CFRunLoopRemoveSource(CFRunLoopGetCurrent(),
174 mySession
->serverRunLoopSource
,
175 kCFRunLoopDefaultMode
);
176 CFRelease(mySession
->serverRunLoopSource
);
178 CFMachPortInvalidate(mySession
->serverPort
);
179 CFRelease(mySession
->serverPort
);
181 storePrivate
->server
= MACH_PORT_NULL
;
190 _configclose(mach_port_t server
, int *sc_status
)
192 serverSessionRef mySession
= getSession(server
);
194 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("Close session."));
195 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
200 *sc_status
= __SCDynamicStoreClose(&mySession
->store
);
201 if (*sc_status
!= kSCStatusOK
) {
202 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" __SCDynamicStoreClose(): %s"), SCErrorString(*sc_status
));
207 * Remove the session entry.
209 removeSession(server
);