2 * Copyright (c) 2000-2002 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>
37 static __inline__
void
38 my_CFDictionaryApplyFunction(CFDictionaryRef theDict
,
39 CFDictionaryApplierFunction applier
,
42 CFAllocatorRef myAllocator
;
43 CFDictionaryRef myDict
;
45 myAllocator
= CFGetAllocator(theDict
);
46 myDict
= CFDictionaryCreateCopy(myAllocator
, theDict
);
47 CFDictionaryApplyFunction(myDict
, applier
, context
);
54 __SCDynamicStoreRemoveWatchedKey(SCDynamicStoreRef store
, CFStringRef key
, Boolean isRegex
)
56 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
58 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreRemoveWatchedKey:"));
59 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
60 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" isRegex = %s"), isRegex
? "TRUE" : "FALSE");
62 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
63 return kSCStatusNoStoreSession
; /* you must have an open session to play */
67 * remove key from this sessions notifier list after checking that
68 * it was previously defined.
71 if (!CFSetContainsValue(storePrivate
->reKeys
, key
))
72 return kSCStatusNoKey
; /* sorry, key does not exist in notifier list */
73 CFSetRemoveValue(storePrivate
->reKeys
, key
); /* remove key from this sessions notifier list */
75 if (!CFSetContainsValue(storePrivate
->keys
, key
))
76 return kSCStatusNoKey
; /* sorry, key does not exist in notifier list */
77 CFSetRemoveValue(storePrivate
->keys
, key
); /* remove key from this sessions notifier list */
81 CFStringRef sessionKey
;
83 CFMutableDictionaryRef newInfo
;
85 CFMutableArrayRef newRKeys
;
87 CFMutableArrayRef newRData
;
90 removeContext context
;
92 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), storePrivate
->server
);
94 info
= CFDictionaryGetValue(sessionData
, sessionKey
);
95 newInfo
= CFDictionaryCreateMutableCopy(NULL
, 0, info
);
97 rKeys
= CFDictionaryGetValue(newInfo
, kSCDRegexKeys
);
98 newRKeys
= CFArrayCreateMutableCopy(NULL
, 0, rKeys
);
100 rData
= CFDictionaryGetValue(newInfo
, kSCDRegexData
);
101 newRData
= CFArrayCreateMutableCopy(NULL
, 0, rData
);
103 i
= CFArrayGetFirstIndexOfValue(newRKeys
,
104 CFRangeMake(0, CFArrayGetCount(newRData
)),
106 regexData
= CFArrayGetValueAtIndex(newRData
, i
);
108 context
.store
= storePrivate
;
109 context
.preg
= (regex_t
*)CFDataGetBytePtr(regexData
);
110 my_CFDictionaryApplyFunction(storeData
,
111 (CFDictionaryApplierFunction
)_removeRegexWatcherByKey
,
114 /* remove the regex key */
115 CFArrayRemoveValueAtIndex(newRKeys
, i
);
116 if (CFArrayGetCount(newRKeys
) > 0) {
117 CFDictionarySetValue(newInfo
, kSCDRegexKeys
, newRKeys
);
119 CFDictionaryRemoveValue(newInfo
, kSCDRegexKeys
);
123 /* ...and the compiled expression */
124 regfree((regex_t
*)CFDataGetBytePtr(regexData
));
125 CFArrayRemoveValueAtIndex(newRData
, i
);
126 if (CFArrayGetCount(newRData
) > 0) {
127 CFDictionarySetValue(newInfo
, kSCDRegexData
, newRData
);
129 CFDictionaryRemoveValue(newInfo
, kSCDRegexData
);
133 /* save the updated session data */
134 CFDictionarySetValue(sessionData
, sessionKey
, newInfo
);
137 CFRelease(sessionKey
);
139 CFNumberRef sessionNum
;
142 * We are watching a specific key. As such, update the
143 * store to mark our interest in any changes.
146 sessionNum
= CFNumberCreate(NULL
, kCFNumberIntType
, &storePrivate
->server
);
147 _removeWatcher(sessionNum
, key
);
148 CFRelease(sessionNum
);
156 _notifyremove(mach_port_t server
,
157 xmlData_t keyRef
, /* raw XML bytes */
158 mach_msg_type_number_t keyLen
,
163 serverSessionRef mySession
= getSession(server
);
164 CFStringRef key
; /* key (un-serialized) */
166 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("Remove notification key for this session."));
167 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
169 /* un-serialize the key */
170 if (!_SCUnserialize((CFPropertyListRef
*)&key
, (void *)keyRef
, keyLen
)) {
171 *sc_status
= kSCStatusFailed
;
175 if (!isA_CFString(key
)) {
177 *sc_status
= kSCStatusInvalidArgument
;
181 *sc_status
= __SCDynamicStoreRemoveWatchedKey(mySession
->store
, key
, isRegex
);