2 * Copyright (c) 2000, 2001, 2003, 2004, 2006-2012 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
30 * March 24, 2000 Allan Nathanson <ajn@apple.com>
40 isMySessionKey(CFStringRef sessionKey
, CFStringRef key
)
43 CFStringRef storeSessionKey
;
45 dict
= CFDictionaryGetValue(storeData
, key
);
47 /* if key no longer exists */
51 storeSessionKey
= CFDictionaryGetValue(dict
, kSCDSession
);
52 if (!storeSessionKey
) {
53 /* if this is not a session key */
57 if (!CFEqual(sessionKey
, storeSessionKey
)) {
58 /* if this is not "my" session key */
67 removeAllKeys(SCDynamicStoreRef store
, Boolean isRegex
)
69 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
73 keys
= isRegex
? storePrivate
->patterns
: storePrivate
->keys
;
74 n
= (keys
!= NULL
) ? CFArrayGetCount(keys
) : 0;
77 CFArrayRef keysToRemove
;
79 keysToRemove
= CFArrayCreateCopy(NULL
, keys
);
80 for (i
= 0; i
< n
; i
++) {
81 (void) __SCDynamicStoreRemoveWatchedKey(store
,
82 CFArrayGetValueAtIndex(keysToRemove
, i
),
86 CFRelease(keysToRemove
);
95 __SCDynamicStoreClose(SCDynamicStoreRef
*store
)
100 serverSessionRef mySession
;
101 CFStringRef sessionKey
;
102 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)*store
;
104 if (_configd_trace
) {
105 SCTrace(TRUE
, _configd_trace
,
106 CFSTR("close : %5d\n"),
107 storePrivate
->server
);
110 /* Remove all notification keys and patterns */
111 removeAllKeys(*store
, FALSE
); // keys
112 removeAllKeys(*store
, TRUE
); // patterns
114 /* Remove/cancel any outstanding notification requests. */
115 __MACH_PORT_DEBUG(storePrivate
->notifyPort
!= MACH_PORT_NULL
, "*** __SCDynamicStoreClose", storePrivate
->notifyPort
);
116 (void) __SCDynamicStoreNotifyCancel(*store
);
118 /* Remove any session keys */
119 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), storePrivate
->server
);
120 dict
= CFDictionaryGetValue(sessionData
, sessionKey
);
121 keys
= CFDictionaryGetValue(dict
, kSCDSessionKeys
);
122 if (keys
&& ((keyCnt
= CFArrayGetCount(keys
)) > 0)) {
124 Boolean push
= FALSE
;
126 /* remove session keys */
127 for (i
= 0; i
< keyCnt
; i
++) {
128 if (isMySessionKey(sessionKey
, CFArrayGetValueAtIndex(keys
, i
))) {
129 (void) __SCDynamicStoreRemoveValue(*store
, CFArrayGetValueAtIndex(keys
, i
), TRUE
);
136 (void) __SCDynamicStorePush();
139 CFRelease(sessionKey
);
142 * invalidate and release our run loop source on the server
143 * port (for this client). Then, release the port.
145 mySession
= getSession(storePrivate
->server
);
146 if (mySession
->serverRunLoopSource
) {
147 CFRunLoopSourceInvalidate(mySession
->serverRunLoopSource
);
148 CFRelease(mySession
->serverRunLoopSource
);
149 mySession
->serverRunLoopSource
= NULL
;
151 if (mySession
->serverPort
!= NULL
) {
152 CFMachPortInvalidate(mySession
->serverPort
);
153 CFRelease(mySession
->serverPort
);
154 mySession
->serverPort
= NULL
;
157 storePrivate
->server
= MACH_PORT_NULL
;