]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_notifyremove.c
9463d395a89af5d6f2c511ca7d9d2c4c41e93b3d
[apple/configd.git] / configd.tproj / _notifyremove.c
1 /*
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * Modification History
26 *
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
29 *
30 * March 24, 2000 Allan Nathanson <ajn@apple.com>
31 * - initial revision
32 */
33
34
35 #include "configd.h"
36 #include "session.h"
37 #include "pattern.h"
38
39
40 __private_extern__
41 int
42 __SCDynamicStoreRemoveWatchedKey(SCDynamicStoreRef store, CFStringRef key, Boolean isRegex, Boolean internal)
43 {
44 CFNumberRef sessionNum;
45 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
46
47 if (_configd_verbose) {
48 SCLog(TRUE, LOG_DEBUG, CFSTR("__SCDynamicStoreRemoveWatchedKey:"));
49 SCLog(TRUE, LOG_DEBUG, CFSTR(" key = %@"), key);
50 SCLog(TRUE, LOG_DEBUG, CFSTR(" isRegex = %s"), isRegex ? "TRUE" : "FALSE");
51 }
52
53 if (!store || (storePrivate->server == MACH_PORT_NULL)) {
54 return kSCStatusNoStoreSession; /* you must have an open session to play */
55 }
56
57 if (_configd_trace) {
58 SCTrace(TRUE, _configd_trace,
59 CFSTR("%s : %5d : %s : %@\n"),
60 internal ? "*watch-" : "watch- ",
61 storePrivate->server,
62 isRegex ? "pattern" : "key",
63 key);
64 }
65
66 /*
67 * remove key from this sessions notifier list after checking that
68 * it was previously defined.
69 */
70 if (isRegex) {
71 if (!CFSetContainsValue(storePrivate->patterns, key))
72 return kSCStatusNoKey; /* sorry, key does not exist in notifier list */
73
74 /* remove key from this sessions notifier list */
75 CFSetRemoveValue(storePrivate->patterns, key);
76
77 /* remove this session as a pattern watcher */
78 sessionNum = CFNumberCreate(NULL, kCFNumberIntType, &storePrivate->server);
79 patternRemoveSession(key, sessionNum);
80 CFRelease(sessionNum);
81 } else {
82 if (!CFSetContainsValue(storePrivate->keys, key))
83 return kSCStatusNoKey; /* sorry, key does not exist in notifier list */
84
85 /* remove key from this sessions notifier list */
86 CFSetRemoveValue(storePrivate->keys, key);
87
88 /*
89 * We are watching a specific key. As such, update the
90 * store to mark our interest in any changes.
91 */
92 sessionNum = CFNumberCreate(NULL, kCFNumberIntType, &storePrivate->server);
93 _removeWatcher(sessionNum, key);
94 CFRelease(sessionNum);
95 }
96
97 return kSCStatusOK;
98 }
99
100
101 __private_extern__
102 kern_return_t
103 _notifyremove(mach_port_t server,
104 xmlData_t keyRef, /* raw XML bytes */
105 mach_msg_type_number_t keyLen,
106 int isRegex,
107 int *sc_status
108 )
109 {
110 serverSessionRef mySession = getSession(server);
111 CFStringRef key; /* key (un-serialized) */
112
113 if (_configd_verbose) {
114 SCLog(TRUE, LOG_DEBUG, CFSTR("Remove notification key for this session."));
115 SCLog(TRUE, LOG_DEBUG, CFSTR(" server = %d"), server);
116 }
117
118 /* un-serialize the key */
119 if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
120 *sc_status = kSCStatusFailed;
121 return KERN_SUCCESS;
122 }
123
124 if (!isA_CFString(key)) {
125 *sc_status = kSCStatusInvalidArgument;
126 CFRelease(key);
127 return KERN_SUCCESS;
128 }
129
130 if (!mySession) {
131 *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */
132 CFRelease(key);
133 return KERN_SUCCESS;
134 }
135
136 *sc_status = __SCDynamicStoreRemoveWatchedKey(mySession->store,
137 key,
138 isRegex != 0,
139 FALSE);
140 CFRelease(key);
141
142 return KERN_SUCCESS;
143 }
144