2 * Copyright (c) 2000-2004, 2006, 2008, 2010-2012, 2015, 2016 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>
41 removeKey(CFMutableArrayRef keys
, CFStringRef key
)
47 /* sorry, empty notifier list */
48 return kSCStatusNoKey
;
51 n
= CFArrayGetCount(keys
);
52 i
= CFArrayGetFirstIndexOfValue(keys
, CFRangeMake(0, n
), key
);
53 if (i
== kCFNotFound
) {
54 /* sorry, key does not exist in notifier list */
55 return kSCStatusNoKey
;
58 /* remove key from this sessions notifier list */
59 CFArrayRemoveValueAtIndex(keys
, i
);
66 __SCDynamicStoreRemoveWatchedKey(SCDynamicStoreRef store
, CFStringRef key
, Boolean isRegex
, Boolean internal
)
68 int sc_status
= kSCStatusOK
;
69 CFNumberRef sessionNum
;
70 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
72 SC_trace("%s : %5d : %s : %@",
73 internal
? "*watch-" : "watch- ",
75 isRegex
? "pattern" : "key",
79 * remove key from this sessions notifier list after checking that
80 * it was previously defined.
83 sc_status
= removeKey(storePrivate
->patterns
, key
);
84 if (sc_status
!= kSCStatusOK
) {
88 /* remove this session as a pattern watcher */
89 sessionNum
= CFNumberCreate(NULL
, kCFNumberIntType
, &storePrivate
->server
);
90 patternRemoveSession(key
, sessionNum
);
91 CFRelease(sessionNum
);
93 sc_status
= removeKey(storePrivate
->keys
, key
);
94 if (sc_status
!= kSCStatusOK
) {
99 * We are watching a specific key. As such, update the
100 * store to remove our interest in any changes.
102 sessionNum
= CFNumberCreate(NULL
, kCFNumberIntType
, &storePrivate
->server
);
103 _removeWatcher(sessionNum
, key
);
104 CFRelease(sessionNum
);
115 _notifyremove(mach_port_t server
,
116 xmlData_t keyRef
, /* raw XML bytes */
117 mach_msg_type_number_t keyLen
,
122 CFStringRef key
= NULL
; /* key (un-serialized) */
123 serverSessionRef mySession
;
125 /* un-serialize the key */
126 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
127 *sc_status
= kSCStatusFailed
;
131 if (!isA_CFString(key
)) {
132 *sc_status
= kSCStatusInvalidArgument
;
136 mySession
= getSession(server
);
137 if (mySession
== NULL
) {
138 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
142 *sc_status
= __SCDynamicStoreRemoveWatchedKey(mySession
->store
,
149 if (key
) CFRelease(key
);