]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_notifyremove.c
710d2e03c5ffe0be1760b5264746dc990fc9edd9
[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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26 /*
27 * Modification History
28 *
29 * June 1, 2001 Allan Nathanson <ajn@apple.com>
30 * - public API conversion
31 *
32 * March 24, 2000 Allan Nathanson <ajn@apple.com>
33 * - initial revision
34 */
35
36
37 #include "configd.h"
38 #include "session.h"
39 #include "pattern.h"
40
41
42 __private_extern__
43 int
44 __SCDynamicStoreRemoveWatchedKey(SCDynamicStoreRef store, CFStringRef key, Boolean isRegex, Boolean internal)
45 {
46 CFNumberRef sessionNum;
47 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
48
49 if (_configd_verbose) {
50 SCLog(TRUE, LOG_DEBUG, CFSTR("__SCDynamicStoreRemoveWatchedKey:"));
51 SCLog(TRUE, LOG_DEBUG, CFSTR(" key = %@"), key);
52 SCLog(TRUE, LOG_DEBUG, CFSTR(" isRegex = %s"), isRegex ? "TRUE" : "FALSE");
53 }
54
55 if (!store || (storePrivate->server == MACH_PORT_NULL)) {
56 return kSCStatusNoStoreSession; /* you must have an open session to play */
57 }
58
59 if (_configd_trace) {
60 SCTrace(TRUE, _configd_trace,
61 CFSTR("%s : %5d : %s : %@\n"),
62 internal ? "*watch-" : "watch- ",
63 storePrivate->server,
64 isRegex ? "pattern" : "key",
65 key);
66 }
67
68 /*
69 * remove key from this sessions notifier list after checking that
70 * it was previously defined.
71 */
72 if (isRegex) {
73 if (!CFSetContainsValue(storePrivate->patterns, key))
74 return kSCStatusNoKey; /* sorry, key does not exist in notifier list */
75
76 /* remove key from this sessions notifier list */
77 CFSetRemoveValue(storePrivate->patterns, key);
78
79 /* remove this session as a pattern watcher */
80 sessionNum = CFNumberCreate(NULL, kCFNumberIntType, &storePrivate->server);
81 patternRemoveSession(key, sessionNum);
82 CFRelease(sessionNum);
83 } else {
84 if (!CFSetContainsValue(storePrivate->keys, key))
85 return kSCStatusNoKey; /* sorry, key does not exist in notifier list */
86
87 /* remove key from this sessions notifier list */
88 CFSetRemoveValue(storePrivate->keys, key);
89
90 /*
91 * We are watching a specific key. As such, update the
92 * store to mark our interest in any changes.
93 */
94 sessionNum = CFNumberCreate(NULL, kCFNumberIntType, &storePrivate->server);
95 _removeWatcher(sessionNum, key);
96 CFRelease(sessionNum);
97 }
98
99 return kSCStatusOK;
100 }
101
102
103 __private_extern__
104 kern_return_t
105 _notifyremove(mach_port_t server,
106 xmlData_t keyRef, /* raw XML bytes */
107 mach_msg_type_number_t keyLen,
108 int isRegex,
109 int *sc_status
110 )
111 {
112 serverSessionRef mySession = getSession(server);
113 CFStringRef key; /* key (un-serialized) */
114
115 if (_configd_verbose) {
116 SCLog(TRUE, LOG_DEBUG, CFSTR("Remove notification key for this session."));
117 SCLog(TRUE, LOG_DEBUG, CFSTR(" server = %d"), server);
118 }
119
120 /* un-serialize the key */
121 if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
122 *sc_status = kSCStatusFailed;
123 return KERN_SUCCESS;
124 }
125
126 if (!isA_CFString(key)) {
127 *sc_status = kSCStatusInvalidArgument;
128 CFRelease(key);
129 return KERN_SUCCESS;
130 }
131
132 if (!mySession) {
133 *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */
134 CFRelease(key);
135 return KERN_SUCCESS;
136 }
137
138 *sc_status = __SCDynamicStoreRemoveWatchedKey(mySession->store,
139 key,
140 isRegex != 0,
141 FALSE);
142 CFRelease(key);
143
144 return KERN_SUCCESS;
145 }
146