2 * Copyright (c) 2000, 2001, 2003, 2004, 2006-2012, 2015, 2016, 2019 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
)
97 serverSessionRef mySession
;
98 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)*store
;
100 SC_trace("close : %5d",
101 storePrivate
->server
);
103 /* Remove all notification keys and patterns */
104 removeAllKeys(*store
, FALSE
); // keys
105 removeAllKeys(*store
, TRUE
); // patterns
107 /* Remove/cancel any outstanding notification requests. */
108 __MACH_PORT_DEBUG(storePrivate
->notifyPort
!= MACH_PORT_NULL
, "*** __SCDynamicStoreClose", storePrivate
->notifyPort
);
109 (void) __SCDynamicStoreNotifyCancel(*store
);
111 /* Remove any session keys */
112 mySession
= getSession(storePrivate
->server
);
113 if (mySession
->sessionKeys
!= NULL
) {
114 CFIndex n
= CFArrayGetCount(mySession
->sessionKeys
);
115 Boolean push
= FALSE
;
116 CFStringRef sessionKey
;
118 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), storePrivate
->server
);
119 for (CFIndex i
= 0; i
< n
; i
++) {
120 CFStringRef key
= CFArrayGetValueAtIndex(mySession
->sessionKeys
, i
);
122 if (isMySessionKey(sessionKey
, key
)) {
123 (void) __SCDynamicStoreRemoveValue(*store
, key
, TRUE
);
127 CFRelease(sessionKey
);
131 (void) __SCDynamicStorePush();
135 storePrivate
->server
= MACH_PORT_NULL
;